import{U as A,b0 as T,r as a,A as v,x as O,i as q,j as o,z as F,a_ as U,l as B,T as j,B as E,y as u,b1 as L}from"./index-cc84e56a.js";import{F as G}from"./Tabla-eb9206ac.js";import{I as V}from"./ImageViewerModal-6b52c15d.js";import"./Edit-5a622c9b.js";import"./ListItemIcon-77037982.js";import"./cjs-0b69d496.js";import"./env-198ff0f3.js";import"./NoRowsComponent-73b1b6ea.js";const k=async n=>await A.get(`${T}${JSON.stringify({url:n})}`),Q=n=>{const{empresaActual:l}=a.useContext(v),[s,d]=a.useState(!1),[f,g]=a.useState(""),b=O(),[h,I]=a.useState(""),[M,y]=a.useState(""),[c,w]=a.useState(""),[C,S]=a.useState([]);a.useEffect(()=>{q.getProcByUsrEmp().then(e=>{S(e.map(t=>({...t,ProcConf:t.ProcNom,id:t.ProcId})))}).catch(e=>{console.error(e)}).finally(()=>{})},[]);const P=()=>{d(!s)},x=()=>{b("/dashboard/template/create")},N=e=>{let t="";e!==null&&(t="cht.ProcId = "+e.ProcId),w(e),m(p=>({...p,query:{...p.query,whereAdicion:t}}))},[r,m]=a.useState({tabla:"chttemplates",campoId:"templateId",configuracion:{permiteBorrar:!0,permiteCrear:!0,permiteSubirArchivo:{permite:!0,campoId:"imagenUrl"},buttons:[{title:"Crear twilio template",fn:x}],defaultValues:{contentType:"libre",esTwilioTemplate:"0",empId:l==null?void 0:l.empId}},query:{name:"templateId",type:"supercombobox",dominio:"",tabla:"chttemplates AS cht LEFT JOIN wfproc AS wf ON cht.procId = wf.ProcId LEFT JOIN dmn AS dmn ON (cht.templategroup = dmn.dmnabr AND dmn.dmnfilt = 'tgroup') ",id:"templateId",text:"templateMensaje",where:`cht.empId = ${l.empId}`,otrosCampos:"cht.*, wf.ProcNom, dmn.DmnDet",ordenBy:"",buscado:"",limit:"20"},columnas:[{visible:!0,esId:!0,name:"templateId",disabled:!1,label:"Identificador",type:"text",required:!0},{visible:!0,name:"templateMensaje",disabled:!1,tooltip:"No se permite la edición del mensaje de templates ya creados",label:"Mensaje",type:"text",multiline:!0,required:!0},{visible:!0,disabled:!1,label:"Proceso",name:"procId",type:"supercombobox",tabla:"wfproc p, wfseq s, wfcomerprc w",id:"p.ProcId",text:"p.ProcNom",dominio:"",otrosCampos:"s.TarId, p.*,s.SeqId",where:"p.ProcId = s.ProcId AND s.SeqTip = 'INI' AND w.ProcId = p.ProcId",whereCallback:()=>`p.EmpId = ${l==null?void 0:l.empId}`,groupBy:"p.ProcId",recargaAlAbrir:!0},{visible:!0,disabled:!1,name:"templateGroup",type:"supercombobox",label:"Grupo",tabla:"dmn",id:"DmnAbr",text:"DmnDet",dominio:"",otrosCampos:"",where:"DmnFilt = 'TGROUP' OR (DmnFilt = 'TGROUP' AND DmnAbr LIKE '%%')"},{visible:!0,name:"templateDetalle",disabled:!1,label:"Detalle",type:"text",multiline:!0},{visible:!0,disabled:!1,label:"Imagen",type:"file",name:"imagenUrl"}],tablaColDef:[{field:"templateId",headerName:"Identificador",type:"number",width:250,align:"left",headerAlign:"left"},{field:"templateMensaje",headerName:"Mensaje",type:"string",width:500,align:"left",headerAlign:"left"},{field:"imagenUrl",headerName:"Image URL",type:"string",width:150,align:"left",headerAlign:"left",renderCell:e=>e.row.imagenUrl.length===0||e.row.imagenUrl==="0"?o("p",{children:"Sin imagen"}):o("strong",{children:o(F,{variant:"contained",size:"small",sx:{color:"#FFF"},onClick:async()=>{const t=await k(e.row.imagenUrl);t&&(P(),g(t.data))},children:"Ver imagen"})})},{field:"ProcNom",headerName:"Proceso",type:"string",width:150,align:"left",headerAlign:"left"},{field:"DmnDet",headerName:"Grupo",type:"string",width:120,align:"left",headerAlign:"left"},{field:"contentType",headerName:"Tipo",type:"string",width:120,align:"left",headerAlign:"left"}],filtros:[]}),i=a.useCallback(U.debounce(async e=>{y(e),m(t=>({...t,query:{...t.query,buscado:e}}))},1200),[]),D=e=>{const t=e.target.value;I(t),i(t)};return a.useEffect(()=>()=>{i.cancel()},[i]),B("div",{children:[o(j,{variant:"h4",component:"h1",gutterBottom:!0,children:"Chat Templates"}),o(E,{children:o(u,{fullWidth:!0,label:"Buscar...",variant:"outlined",value:h,onChange:D})}),o(L,{fullWidth:!0,options:C,getOptionLabel:e=>e.ProcNom,value:c===void 0?null:c,sx:{marginTop:1},renderInput:e=>o(u,{...e,label:"Seleccione un proceso",variant:"outlined"}),onChange:(e,t)=>{console.log("Proceso seleccionado:",t),N(t)}}),o(G,{tabla:r.tabla,title:r.title,configuracion:r.configuracion,query:r.query,columnasData:r.columnas,tablaColDef:r.tablaColDef,campoId:r.campoId,filtros:r.filtros}),o(V,{src:f,setShowDialog:d,showDialog:s})]})};export{Q as default};
