import{W as A,ba as T,r as a,A as v,x as q,i as F,j as o,z as O,b8 as B,l as U,T as j,B as E,y as u,bb as L}from"./index-91e9700c.js";import{F as G}from"./Tabla-24cfbe18.js";import{I as V}from"./ImageViewerModal-ecc62c6d.js";import"./Edit-4ff74b50.js";import"./ListItemIcon-370ea8d8.js";import"./cjs-e9b09402.js";import"./env-198ff0f3.js";import"./NoRowsComponent-87124367.js";import"./DialogContentText-3801f418.js";const k=async n=>await A.post(`${T}`,{url:n}),Y=n=>{const{empresaActual:l}=a.useContext(v),[s,d]=a.useState(!1),[b,f]=a.useState(""),g=q(),[h,I]=a.useState(""),[M,y]=a.useState(""),[c,w]=a.useState(""),[C,P]=a.useState([]);a.useEffect(()=>{F.getProcByUsrEmp().then(e=>{P(e.map(t=>({...t,ProcConf:t.ProcNom,id:t.ProcId})))}).catch(e=>{console.error(e)}).finally(()=>{})},[]);const S=()=>{d(!s)},x=()=>{g("/dashboard/template/create")},D=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(O,{variant:"contained",size:"small",sx:{color:"#FFF"},onClick:async()=>{const t=await k(e.row.imagenUrl);t&&(S(),f(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),[]),N=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:h,onChange:N})}),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),D(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:b,setShowDialog:d,showDialog:s})]})};export{Y as default};
