import{i as x}from"./emotion-use-insertion-effect-with-fallbacks.browser.esm-6809063d.js";import{a as n,j as w}from"./Tooltip-ae8d7992.js";import{O as L,D as y}from"./OmegaTransferList-97b6210a.js";import{A as H,i as h,v as N,h as $,O as q,L as F,w as S,z as P}from"./index-dfa17bed.js";const{Box:b}=await x("@mui/material"),{useContext:D,useEffect:I,useState:o}=await x("react"),Q=G=>{o([]),o([]);const[T,j]=o(!1),[E,O]=o(!1),[t,l]=o([]),[c,d]=o([]),[i,A]=o(""),{empresaActual:u}=D(H),m=e=>e.map(r=>({id:r.PrfId,...r}));I(()=>{i.length!==0&&p(i).then(e=>console.log(e)).catch(e=>console.log(e))},[i]),I(()=>{console.log("perfilesEstan",t)},[t]);const C=e=>{if(e.length===0)return;console.log("tareas es",t);const r=t.map(a=>({PrfId:a.PrfId}));h.post(`${S}`,{e,s:u?.empId,d:r}).then(a=>{P.success("Perfiles agregados con éxito"),p(e),a.data.success}).catch(a=>{P.error("Error al guardar"),console.error(a)}).finally(()=>O(!1))},p=async e=>{try{const r=await h.post(`${N}`,{t:e,s:u?.empId});console.log("res",r),r.data&&(l(m(r.data.estan)),d(m(r.data.noestan)))}catch(r){console.error("Error al obtener datos obtenerPaquetes:",r)}},g=[{field:"PrfNom",headerName:"Perfil",width:200}],U=(e,r)=>{if(r===y.DERECHA){const a=c.filter(s=>e.includes(`${s.PrfId}`));console.log("nuevaProcOrgHabilitadas",a),l(s=>[...s,...a]);const f=c.filter(s=>!e.includes(`${s.PrfId}`));d(f)}else{const a=t.filter(s=>!e.includes(`${s.PrfId}`));l(a);const f=t.filter(s=>e.includes(`${s.PrfId}`));d(s=>[...s,...f])}},{control:v,watch:z,formState:B,handleSubmit:V,resetField:k}=$({mode:"onChange",defaultValues:{UsrId:""}});return n("div",{children:w(b,{children:[n(q,{control:v,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=>{A(e.id)}}),n(b,{mt:2,children:n(L,{columns:g,columnsTransferidos:g,itemsLoading:T,deshabilitaAcciones:!1,titulos:{sinTransferir:"Tareas que no estan en el paquete",transferidos:"Tareas que si estan en el paquete"},transferirItems:U,itemsSinTransferir:c,itemsTransferidos:t,height:"400px"})}),n(F,{loading:E,type:"button",fullWidth:!0,variant:"outlined",onClick:()=>C(i),style:{marginTop:"10px"},children:"Guardar"})]})})};export{Q as default};
