import{r as a,A as U,$ as P,bj as v,h as y,j as i,o as L,B as h,O as $,aE as H,bk as N,W as b}from"./index-62412d73.js";import{O as q,D as w}from"./OmegaTransferList-dd2e3814.js";import"./NoRowsComponent-60007845.js";import"./Card-9a848e01.js";import"./CardHeader-b8f95819.js";const K=A=>{a.useState([]),a.useState([]);const[I,F]=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&&p(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(`${N}`,{e,s:n==null?void 0:n.empId,d:r}).then(t=>{b.success("Perfiles agregados con éxito"),p(e),t.data.success}).catch(t=>{b.error("Error al guardar"),console.error(t)}).finally(()=>E(!1))},p=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)}},m=[{field:"PrfNom",headerName:"Perfil",width:200}],S=(e,r)=>{if(r===w.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:j,formState:B,handleSubmit:D,resetField:G}=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(q,{columns:m,columnsTransferidos:m,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(H,{loading:x,type:"button",fullWidth:!0,variant:"outlined",onClick:()=>O(l),style:{marginTop:"10px"},children:"Guardar"})]})})};export{K as default};
