import{r as a,A as U,$ as P,bl as v,h as y,j as i,o as L,B as h,O as $,aF as F,bm as H,W as b}from"./index-e717fda1.js";import{O as N,D as q}from"./OmegaTransferList-29984757.js";import"./NoRowsComponent-28b18b21.js";import"./Card-4256f0c9.js";import"./CardHeader-f20ec4a9.js";const K=w=>{a.useState([]),a.useState([]);const[I,A]=a.useState(!1),[x,E]=a.useState(!1),[o,d]=a.useState([]),[c,f]=a.useState([]),[l,T]=a.useState(""),{empresaActual:n}=a.useContext(U),g=e=>e.map(r=>({id:r.PrfId,...r}));a.useEffect(()=>{l.length!==0&&m(l).then(e=>console.log(e)).catch(e=>console.log(e))},[l]),a.useEffect(()=>{console.log("perfilesEstan",o)},[o]);const O=e=>{if(e.length===0)return;console.log("tareas es",o);const r=o.map(t=>({PrfId:t.PrfId}));P.post(`${H}`,{e,s:n==null?void 0:n.empId,d:r}).then(t=>{b.success("Perfiles agregados con éxito"),m(e),t.data.success}).catch(t=>{b.error("Error al guardar"),console.error(t)}).finally(()=>E(!1))},m=async e=>{try{const r=await P.post(`${v}`,{t:e,s:n==null?void 0:n.empId});console.log("res",r),r.data&&(d(g(r.data.estan)),f(g(r.data.noestan)))}catch(r){console.error("Error al obtener datos obtenerPaquetes:",r)}},p=[{field:"PrfNom",headerName:"Perfil",width:200}],S=(e,r)=>{if(r===q.DERECHA){const t=c.filter(s=>e.includes(`${s.PrfId}`));console.log("nuevaProcOrgHabilitadas",t),d(s=>[...s,...t]);const u=c.filter(s=>!e.includes(`${s.PrfId}`));f(u)}else{const t=o.filter(s=>!e.includes(`${s.PrfId}`));d(t);const u=o.filter(s=>e.includes(`${s.PrfId}`));f(s=>[...s,...u])}},{control:C,watch:B,formState:D,handleSubmit:G,resetField:j}=y({mode:"onChange",defaultValues:{UsrId:""}});return i("div",{children:L(h,{children:[i($,{control:C,name:"PrfId",type:"supercombobox",iField:{id:"UsrId",name:"UsrId",text:'CONCAT(UsrApel," ",UsrNom)',type:"supercombobox",tabla:"usr",where:"",recargaAlAbrir:!1},label:"Perfil de usuario",watchValue:e=>{T(e.id)}}),i(h,{mt:2,children:i(N,{columns:p,columnsTransferidos:p,itemsLoading:I,deshabilitaAcciones:!1,titulos:{sinTransferir:"Tareas que no estan en el paquete",transferidos:"Tareas que si estan en el paquete"},transferirItems:S,itemsSinTransferir:c,itemsTransferidos:o,height:"400px"})}),i(F,{loading:x,type:"button",fullWidth:!0,variant:"outlined",onClick:()=>O(l),style:{marginTop:"10px"},children:"Guardar"})]})})};export{K as default};
