import{a2 as A,bq as v,r as a,A as T,K as q,m as U,j as o,M as F,ag as O,o as B,y as L,B as j,L as f,br as E}from"./index-e47c07e2.js";import{F as R}from"./Tabla-6a37d2b7.js";import{I as k}from"./ImageViewerModal-1f595c1c.js";import"./Edit-7425426d.js";import"./ListItemIcon-49470498.js";import"./cjs-e4e77118.js";import"./NoRowsComponent-7f6e8fc1.js";import"./DialogContentText-bbf9f64d.js";const G=async s=>await A.post(`${v}`,{url:s}),X=s=>{const{empresaActual:r}=a.useContext(T),[d,c]=a.useState(!1),[b,m]=a.useState(""),g=q(),[I,y]=a.useState(""),[M,w]=a.useState(""),[p,C]=a.useState(""),[P,S]=a.useState([]);a.useEffect(()=>{U.getProcByUsrEmp().then(t=>{S(t.map(e=>({...e,ProcConf:e.ProcNom,id:e.ProcId})))}).catch(t=>{console.error(t)}).finally(()=>{})},[]);const u=()=>{c(!d)},x=()=>{g("/dashboard/template/create")},D=t=>{let e="";t!==null&&(e="cht.ProcId = "+t.ProcId),C(t),h(n=>({...n,query:{...n.query,whereAdicion:e}}))},[l,h]=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: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:t=>t.row.imagenUrl.length===0||t.row.imagenUrl==="0"?o("p",{children:"Sin imagen"}):o("strong",{children:o(F,{variant:"contained",size:"small",sx:{color:"#FFF"},onClick:async()=>{const e=await G(t.row.imagenUrl);if(console.log("res",e),e)try{new URL(e.data).pathname.toLowerCase().endsWith(".pdf")?window.open(e.data,"_blank"):(u(),m(e.data))}catch(n){console.error("URL inválida:",e.data,n),u(),m(e.data)}},children:"Ver archivo"})})},{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(O.debounce(async t=>{w(t),h(e=>({...e,query:{...e.query,buscado:t}}))},1200),[]),N=t=>{const e=t.target.value;y(e),i(e)};return a.useEffect(()=>()=>{i.cancel()},[i]),B("div",{children:[o(L,{variant:"h4",component:"h1",gutterBottom:!0,children:"Chat Templates"}),o(j,{children:o(f,{fullWidth:!0,label:"Buscar...",variant:"outlined",value:I,onChange:N})}),o(E,{fullWidth:!0,options:P,getOptionLabel:t=>t.ProcNom,value:p===void 0?null:p,sx:{marginTop:1},renderInput:t=>o(f,{...t,label:"Seleccione un proceso",variant:"outlined"}),onChange:(t,e)=>{console.log("Proceso seleccionado:",e),D(e)}}),o(R,{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(k,{src:b,setShowDialog:c,showDialog:d})]})};export{X as default};
