import{c as f,j as e}from"./index-D9pJRAs5.js";import{r as n}from"./vendor-D6aTFYy9.js";import j from"./AddEditRoleModal-DG7N6JGN.js";import{r as y,aC as N,aU as k,ar as v}from"./ui-CtYVlq7P.js";import"./pdf-Bz_mU5mG.js";const E=()=>{const{roles:d,addRole:i,updateRole:o,deleteRole:x,users:c}=f(),[m,r]=n.useState(!1),[u,l]=n.useState(null),g=()=>{l(null),r(!0)},h=s=>{l(s),r(!0)},p=(s,t)=>{t?o(t,s):i(s),r(!1)},b=s=>{window.confirm("Are you sure you want to delete this role? This cannot be undone.")&&x(s)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Roles & Permissions"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Define roles and assign permissions to control user access."})]}),e.jsxs("button",{onClick:g,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors flex items-center space-x-2",children:[e.jsx(y,{className:"h-4 w-4"}),e.jsx("span",{children:"Add Role"})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:d.map(s=>{const t=c.filter(a=>a.role.toLowerCase()===s.name.toLowerCase()).length;return e.jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 p-6 rounded-xl border border-gray-200 dark:border-gray-700 flex flex-col",children:[e.jsxs("div",{className:"flex-grow",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("h3",{className:"text-xl font-bold text-gray-900 dark:text-white",children:s.name}),e.jsxs("div",{className:"flex items-center text-sm text-gray-500 dark:text-gray-400",children:[e.jsx(N,{className:"h-4 w-4 mr-1"}),t]})]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 min-h-[40px]",children:s.description}),e.jsxs("div",{className:"mt-4",children:[e.jsx("h4",{className:"text-xs font-semibold uppercase text-gray-500 dark:text-gray-400 mb-2",children:"Permissions"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.permissions.slice(0,5).map(a=>e.jsx("span",{className:"px-2 py-1 text-xs bg-blue-100 text-blue-800 dark:bg-blue-900/50 dark:text-blue-300 rounded-full",children:a},a)),s.permissions.length>5&&e.jsxs("span",{className:"text-xs text-gray-500",children:["+",s.permissions.length-5," more"]}),s.permissions.includes("all")&&e.jsx("span",{className:"px-2 py-1 text-xs bg-green-100 text-green-800 dark:bg-green-900/50 dark:text-green-300 rounded-full",children:"All Permissions"})]})]})]}),e.jsxs("div",{className:"mt-6 pt-4 border-t border-gray-200 dark:border-gray-700 flex justify-end space-x-2",children:[e.jsx("button",{onClick:()=>h(s),className:"p-2 text-blue-600 hover:bg-blue-100 rounded-full dark:hover:bg-blue-900/50",children:e.jsx(k,{size:16})}),e.jsx("button",{onClick:()=>b(s.id),className:"p-2 text-red-600 hover:bg-red-100 rounded-full dark:hover:bg-red-900/50",children:e.jsx(v,{size:16})})]})]},s.id)})}),e.jsx(j,{isOpen:m,onClose:()=>r(!1),onSave:p,role:u})]})};export{E as default};
