import{u as v,j as e}from"./index-D9pJRAs5.js";import{r as o}from"./vendor-D6aTFYy9.js";import{X as w,n as f}from"./ui-CtYVlq7P.js";import"./pdf-Bz_mU5mG.js";const b={dashboard:{label:"Dashboard",permissions:{"dashboard:view":"View Dashboard"}},orders:{label:"Orders & Quotes",permissions:{"orders:view":"View All Orders & Quotes","orders:view_own":"View Own Orders & Quotes (Customer)","orders:create":"Create New Orders/Quotes","orders:edit":"Edit Orders/Quotes","orders:delete":"Delete Orders/Quotes"}},production:{label:"Production",permissions:{"production:view":"View Production Modules","production:update_status":"Update Production Status","production:manage_workflow":"Manage Production Workflow"}},quality_control:{label:"Quality Control",permissions:{"quality:view":"View Quality Control Module","quality:perform_checks":"Perform Quality Checks"}},inventory:{label:"Inventory",permissions:{"inventory:view":"View Inventory","inventory:edit":"Manage Stock Levels"}},accounting:{label:"Accounting",permissions:{"accounting:view":"View Accounting Modules","accounting:manage_invoices":"Manage Invoices & Payments","accounting:manage_expenses":"Manage Expenses","accounting:view_reports":"View Financial Reports"}},hr:{label:"HR & Payroll",permissions:{"hr:view":"View HR & Payroll","hr:manage_employees":"Manage Employees","hr:run_payroll":"Run Payroll"}},analytics:{label:"Analytics",permissions:{"analytics:view":"View Analytics Dashboard"}},administration:{label:"Administration",permissions:{"admin:view":"View Administration Panel","admin:manage_users":"Manage Users","admin:manage_roles":"Manage Roles & Permissions","admin:manage_system":"Manage System Settings"}}};Object.values(b).flatMap(t=>Object.entries(t.permissions).map(([l,d])=>({id:l,label:d,module:t.label})));const P=({isOpen:t,onClose:l,onSave:d,role:a})=>{const{t:r}=v(),[g,c]=o.useState(""),[x,m]=o.useState(""),[p,u]=o.useState([]);o.useEffect(()=>{t&&(a?(c(a.name),m(a.description),u(a.permissions)):(c(""),m(""),u([])))},[t,a]);const y=s=>{u(n=>n.includes(s)?n.filter(i=>i!==s):[...n,s])},h=s=>{s.preventDefault(),d({name:g,description:x,permissions:p},a==null?void 0:a.id)};return t?e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-[60]",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 rounded-2xl max-w-3xl w-full max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b dark:border-gray-700 flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white",children:r(a?"admin.roles.editRole":"admin.roles.addRole")}),e.jsx("button",{onClick:l,className:"p-2 text-gray-400 hover:text-gray-600 rounded-lg",children:e.jsx(w,{})})]}),e.jsxs("form",{onSubmit:h,className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:r("admin.roles.roleName")}),e.jsx("input",{type:"text",value:g,onChange:s=>c(s.target.value),className:"w-full mt-1 p-2 border rounded-lg dark:bg-gray-700 dark:border-gray-600",required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:r("admin.roles.description")}),e.jsx("input",{type:"text",value:x,onChange:s=>m(s.target.value),className:"w-full mt-1 p-2 border rounded-lg dark:bg-gray-700 dark:border-gray-600",required:!0})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:r("admin.roles.permissions")}),e.jsx("div",{className:"space-y-4",children:Object.entries(b).map(([s,n])=>e.jsxs("div",{className:"p-4 border dark:border-gray-700 rounded-lg bg-gray-50 dark:bg-gray-700/50",children:[e.jsx("h4",{className:"font-semibold mb-2 text-gray-800 dark:text-gray-200",children:r(`permissions.modules.${s}`)}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:Object.entries(n.permissions).map(([i])=>e.jsxs("label",{className:"flex items-center space-x-2 text-sm text-gray-700 dark:text-gray-300",children:[e.jsx("input",{type:"checkbox",checked:p.includes(i),onChange:()=>y(i),className:"h-4 w-4 text-blue-600 rounded focus:ring-blue-500"}),e.jsx("span",{children:r(`permissions.${i}`)})]},i))})]},s))})]}),e.jsxs("div",{className:"pt-4 flex justify-end space-x-3",children:[e.jsx("button",{type:"button",onClick:l,className:"px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 dark:bg-gray-600 dark:text-gray-200 dark:hover:bg-gray-500",children:r("admin.roles.cancel")}),e.jsxs("button",{type:"submit",className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 flex items-center space-x-2",children:[e.jsx(f,{className:"h-4 w-4"}),e.jsx("span",{children:r("admin.roles.saveRole")})]})]})]})]})}):null};export{P as default};
