import{y as A,aR as T,r as a,A as v,k as O,aS as q,j as o,m as F,aQ as B,f as U,T as j,B as E,l as u,aT as L}from"./index-4e7882bc.js";import{F as k}from"./Tabla-77abadee.js";import{I as G}from"./ImageViewerModal-8b66f0f6.js";import"./NoRowsComponent-94f1c2bb.js";import"./DataGrid-c017cd02.js";import"./toPropertyKey-4015efc6.js";import"./dividerClasses-9982a278.js";import"./listItemTextClasses-0d3e3a1a.js";import"./ListItemIcon-95e7eb22.js";import"./cjs-cef02a75.js";import"./env-198ff0f3.js";const R=async n=>await A.get(`${T}${JSON.stringify({url:n})}`),_=n=>{const{empresaActual:r}=a.useContext(v),[s,d]=a.useState(!1),[f,g]=a.useState(""),h=O(),[b,I]=a.useState(""),[V,y]=a.useState(""),[c,w]=a.useState(""),[S,C]=a.useState([]);a.useEffect(()=>{q.getProcByUsrEmp().then(e=>{C(e.map(t=>({...t,ProcConf:t.ProcNom,id:t.ProcId})))}).catch(e=>{console.error(e)}).finally(()=>{})},[]);const P=()=>{d(!s)},N=()=>{h("/dashboard/template/create")},x=e=>{let t="";e!==null&&(t="cht.ProcId = "+e.ProcId),w(e),m(p=>({...p,query:{...p.query,whereAdicion:t}}))},[l,m]=a.useState({tabla:"chttemplates",campoId:"templateId",configuracion:{permiteBorrar:!0,permiteCrear:!0,permiteSubirArchivo:{permite:!0,campoId:"imagenUrl"},buttons:[{title:"Crear twilio template",fn:N}],defaultValues:{contentType:"libre",esTwilioTemplate:"0",empId:r==null?void 0:r.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 = ${r.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 = ${r==null?void 0:r.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 R(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(B.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]),U("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:b,onChange:D})}),o(L,{fullWidth:!0,options:S,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),x(t)}}),o(k,{tabla:l.tabla,title:l.title,configuracion:l.configuracion,query:l.query,columnasData:l.columnas,tablaColDef:l.tablaColDef,campoId:l.campoId,filtros:l.filtros}),o(G,{src:f,setShowDialog:d,showDialog:s})]})};export{_ as default};
