var j=Object.defineProperty,p=Object.defineProperties;var N=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var y=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var h=(r,s,a)=>s in r?j(r,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):r[s]=a,g=(r,s)=>{for(var a in s||(s={}))y.call(s,a)&&h(r,a,s[a]);if(x)for(var a of x(s))b.call(s,a)&&h(r,a,s[a]);return r},f=(r,s)=>p(r,N(s));var m=(r,s,a)=>new Promise((o,c)=>{var t=n=>{try{i(a.next(n))}catch(d){c(d)}},l=n=>{try{i(a.throw(n))}catch(d){c(d)}},i=n=>n.done?o(n.value):Promise.resolve(n.value).then(t,l);i((a=a.apply(r,s)).next())});import{M as v,j as e,ar as P,B as u,as as C,at as w,au as k}from"./index-C7Y5J1TO.js";import{u as E}from"./useQuery-DGaD2i6Y.js";import{f as R}from"./settings-services-CMNk-eHJ.js";import{B}from"./badge-DLmsfCsp.js";import{C as F,b as S,a as q,e as D}from"./card-DDrJ6Iia.js";import{S as G}from"./switch-9CBoXrWV.js";const K=r=>{const{isPending:s,data:a,isError:o,error:c}=E({queryKey:["getRolePermissions"],queryFn:()=>m(null,null,function*(){const t=yield R(r);if(t.status===200)return t.data.data;throw new Error("Error fetching permissions")})});return{isPending:s,permissions:a,isError:o,error:c}};function U(){const{roleName:r}=v();if(!r)return e.jsx("div",{children:"Error: roleName is missing"});const{permissions:s}=K(r),a=P(),o=t=>{setPermissions(l=>l.map(i=>i.id===t?f(g({},i),{checked:!i.checked}):i))},c=()=>m(null,null,function*(){const t=s.filter(l=>l.checked);console.log("Permisos activos:",t)});return e.jsxs("div",{className:"grid grid-cols-1 gap-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-3xl font-bold text-primary",children:"Asignación de permisos"}),e.jsxs("small",{className:"flex items-center gap-2 text-muted-foreground",children:["Selecciona los permisos que deseas asignar al rol"," ",e.jsx(B,{variant:"info-soft",className:"px-3 font-semibold",children:r})]})]}),e.jsxs(u,{onClick:()=>a(-1),variant:"secondary-soft",className:"flex items-center gap-2",children:[e.jsx(C,{size:18})," Regresar"]})]}),e.jsxs(F,{className:"w-full overflow-hidden bg-thertiary/70",children:[e.jsx(S,{className:"border-b-4 border-thertiary bg-white py-4 leading-tight",children:e.jsxs("h4",{className:"mb-0 flex items-center gap-2",children:[e.jsx(w,{})," ",e.jsx("span",{children:"Formulario de asignación de permisos"})]})}),e.jsx(q,{className:"bg-accent p-6",children:e.jsx("div",{className:"grid grid-cols-3 gap-4",children:s==null?void 0:s.map(t=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(G,{checked:t.checked,onCheckedChange:()=>o(t.id)}),e.jsx("span",{className:"ml-2 text-sm",children:t.name})]},t.id))})}),e.jsx(D,{className:"flex items-center justify-center border-t-4 border-thertiary bg-white py-2",children:e.jsxs(u,{onClick:c,className:"flex items-center justify-center gap-2",children:[e.jsx(k,{})," Guardar cambios"]})})]})]})}export{U as default};
