var p=Object.defineProperty,j=Object.defineProperties;var y=Object.getOwnPropertyDescriptors;var x=Object.getOwnPropertySymbols;var N=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var h=(a,s,r)=>s in a?p(a,s,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[s]=r,f=(a,s)=>{for(var r in s||(s={}))N.call(s,r)&&h(a,r,s[r]);if(x)for(var r of x(s))b.call(s,r)&&h(a,r,s[r]);return a},g=(a,s)=>j(a,y(s));var m=(a,s,r)=>new Promise((c,o)=>{var i=n=>{try{t(r.next(n))}catch(d){o(d)}},l=n=>{try{t(r.throw(n))}catch(d){o(d)}},t=n=>n.done?c(n.value):Promise.resolve(n.value).then(i,l);t((r=r.apply(a,s)).next())});import{j as e}from"./radixui-DBNNXUn7.js";import{g as v,u as P}from"./router-ZPDjRWWZ.js";import{u as C}from"./useQuery-tXf2Qa8J.js";import{f as w}from"./settings-services-C1WB00Jx.js";import{B as u,P as k,M as E,y as R}from"./index-C1-9bQes.js";import{B}from"./badge-BMZJ96FB.js";import{C as F,b as S,a as q,e as D}from"./card-BaxfxC-x.js";import{S as G}from"./switch-D-xviNN8.js";import"./vendor-C0DUGSOM.js";import"./utils-CbOYy0fT.js";import"./icons-DvPHMWAM.js";const K=a=>{const{isPending:s,data:r,isError:c,error:o}=C({queryKey:["getRolePermissions"],queryFn:()=>m(null,null,function*(){const i=yield w(a);if(i.status===200)return i.data.data;throw new Error("Error fetching permissions")})});return{isPending:s,permissions:r,isError:c,error:o}};function W(){const{roleName:a}=v();if(!a)return e.jsx("div",{children:"Error: roleName is missing"});const{permissions:s}=K(a),r=P(),c=i=>{setPermissions(l=>l.map(t=>t.id===i?g(f({},t),{checked:!t.checked}):t))},o=()=>m(null,null,function*(){const i=s.filter(l=>l.checked);console.log("Permisos activos:",i)});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:a})]})]}),e.jsxs(u,{onClick:()=>r(-1),variant:"secondary-soft",className:"flex items-center gap-2",children:[e.jsx(k,{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(E,{})," ",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(i=>e.jsxs("div",{className:"flex items-center",children:[e.jsx(G,{checked:i.checked,onCheckedChange:()=>c(i.id)}),e.jsx("span",{className:"ml-2 text-sm",children:i.name})]},i.id))})}),e.jsx(D,{className:"flex items-center justify-center border-t-4 border-thertiary bg-white py-2",children:e.jsxs(u,{onClick:o,className:"flex items-center justify-center gap-2",children:[e.jsx(R,{})," Guardar cambios"]})})]})]})}export{W as default};
