import{r as t,A as U,a2 as P,bu as v,h as L,j as i,o as y,B as h,O as H,aL as N,bv as $,Y as b}from"./index-e47c07e2.js";import{O as q,D as w}from"./OmegaTransferList-c97dc0ab.js";import"./NoRowsComponent-7f6e8fc1.js";import"./CardHeader-c1b748f1.js";const Y=A=>{t.useState([]),t.useState([]);const[I,F]=t.useState(!1),[x,E]=t.useState(!1),[o,d]=t.useState([]),[c,u]=t.useState([]),[l,T]=t.useState(""),{empresaActual:n}=t.useContext(U),g=e=>e.map(r=>({id:r.PrfId,...r}));t.useEffect(()=>{l.length!==0&&p(l).then(e=>console.log(e)).catch(e=>console.log(e))},[l]),t.useEffect(()=>{console.log("perfilesEstan",o)},[o]);const O=e=>{if(e.length===0)return;console.log("tareas es",o);const r=o.map(a=>({PrfId:a.PrfId}));P.post(`${$}`,{e,s:n==null?void 0:n.empId,d:r}).then(a=>{b.success("Perfiles agregados con éxito"),p(e),a.data.success}).catch(a=>{b.error("Error al guardar"),console.error(a)}).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)),u(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 a=c.filter(s=>e.includes(`${s.PrfId}`));console.log("nuevaProcOrgHabilitadas",a),d(s=>[...s,...a]);const f=c.filter(s=>!e.includes(`${s.PrfId}`));u(f)}else{const a=o.filter(s=>!e.includes(`${s.PrfId}`));d(a);const f=o.filter(s=>e.includes(`${s.PrfId}`));u(s=>[...s,...f])}},{control:C,watch:B,formState:D,handleSubmit:G,resetField:j}=L({mode:"onChange",defaultValues:{UsrId:""}});return i("div",{children:y(h,{children:[i(H,{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(N,{loading:x,type:"button",fullWidth:!0,variant:"outlined",onClick:()=>O(l),style:{marginTop:"10px"},children:"Guardar"})]})})};export{Y as default};
