import{i as b}from"./emotion-use-insertion-effect-with-fallbacks.browser.esm-2ce7a1bc.js";import{a,j as T}from"./Tooltip-5ec3092e.js";import{F as S}from"./Tabla-74ae8758.js";import{i as v,a0 as U,A as q,c as O,m as F,l as B,a1 as L}from"./index-76588cc8.js";const j=async s=>await v.post(`${U}`,{url:s}),{useCallback:E,useContext:R,useEffect:f,useState:l}=await b("react"),{Box:k,Button:G,TextField:g,Typography:V,Autocomplete:M}=await b("@mui/material"),H=s=>{const{empresaActual:n}=R(q),[d,c]=l(!1),[I,m]=l("");O();const[y,w]=l(""),[W,C]=l(""),[p,A]=l(""),[P,D]=l([]);f(()=>{F.getProcByUsrEmp().then(t=>{D(t.map(e=>({...e,ProcConf:e.ProcNom,id:e.ProcId})))}).catch(t=>{console.error(t)}).finally(()=>{})},[]);const u=()=>{c(!d)},N=t=>{let e="";t!==null&&(e="cht.ProcId = "+t.ProcId),A(t),h(r=>({...r,query:{...r.query,whereAdicion:e}}))},[o,h]=l({tabla:"chttemplates",campoId:"templateId",configuracion:{permiteBorrar:!0,permiteCrear:!0,permiteSubirArchivo:{permite:!0,campoId:"imagenUrl"},buttons:[],defaultValues:{contentType:"libre",esTwilioTemplate:"0",empId:n?.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 = ${n.empId} and cht.contentType = 'libre' and cht.esTwilioTemplate != 1`,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 = ${n?.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"?a("p",{children:"Sin imagen"}):a("strong",{children:a(G,{variant:"contained",size:"small",sx:{color:"#FFF"},onClick:async()=>{const e=await j(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(r){console.error("URL inválida:",e.data,r),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=E(B.debounce(async t=>{C(t),h(e=>({...e,query:{...e.query,buscado:t}}))},1200),[]),x=t=>{const e=t.target.value;w(e),i(e)};return f(()=>()=>{i.cancel()},[i]),T("div",{children:[a(V,{variant:"h4",component:"h1",gutterBottom:!0,children:"Chat Templates"}),a(k,{children:a(g,{fullWidth:!0,label:"Buscar...",variant:"outlined",value:y,onChange:x})}),a(M,{fullWidth:!0,options:P,getOptionLabel:t=>t.ProcNom,value:p===void 0?null:p,sx:{marginTop:1},renderInput:t=>a(g,{...t,label:"Seleccione un proceso",variant:"outlined"}),onChange:(t,e)=>{console.log("Proceso seleccionado:",e),N(e)}}),a(S,{tabla:o.tabla,title:o.title,configuracion:o.configuracion,query:o.query,columnasData:o.columnas,tablaColDef:o.tablaColDef,campoId:o.campoId,filtros:o.filtros}),a(L,{src:I,setShowDialog:c,showDialog:d})]})};export{H as default};
