import{a as e,n as t,t as n}from"./jsx-runtime-B-hcVAMW.js";import{r}from"./api-Duu96wkE.js";import{E as i,j as a,k as o,z as s}from"./index-DyQEyT-0.js";import{t as c}from"./Badge-BGqYAYKM.js";import{t as l}from"./EmptyState-BCP63FMk.js";import{t as u}from"./ErrorState-BkSpMSl3.js";import{a as d,n as f,t as p}from"./hooks-BlgImpkY.js";var m=e(t(),1),h=n();function g(){let{can:e}=o(),{data:t,isPending:n,error:g,refetch:_}=d(),v=p(),y=f(),[b,x]=(0,m.useState)(null);if(n)return(0,h.jsx)(i,{label:`Loading roles`});if(g)return(0,h.jsx)(u,{error:g,onRetry:()=>_()});let S=async(e,t)=>{x(null);try{await v.mutateAsync({name:e,label:`${t} (copy)`})}catch(e){x(r(e).message)}},C=async e=>{x(null);try{await y.mutateAsync(e)}catch(e){x(r(e).message)}};return(0,h.jsxs)(`div`,{className:`space-y-6`,children:[(0,h.jsxs)(`header`,{className:`flex flex-wrap items-end justify-between gap-4`,children:[(0,h.jsxs)(`div`,{children:[(0,h.jsx)(`h1`,{className:`text-xl font-semibold text-slate-900`,children:`Roles & permissions`}),(0,h.jsx)(`p`,{className:`mt-1 text-sm text-slate-500`,children:`Each role grants permissions within an organizational scope. The server enforces both.`})]}),e(`role.create`)&&(0,h.jsx)(s,{to:`/app/settings/roles/new`,children:(0,h.jsx)(a,{children:`New role`})})]}),b&&(0,h.jsx)(u,{error:Error(b)}),t.length===0?(0,h.jsx)(l,{title:`No roles yet`,description:`Seed the default roles or create your first one.`}):(0,h.jsx)(`div`,{className:`overflow-x-auto rounded-xl border border-slate-200 bg-white`,children:(0,h.jsxs)(`table`,{className:`min-w-full divide-y divide-slate-200 text-sm`,children:[(0,h.jsx)(`thead`,{className:`bg-slate-50 text-left text-xs font-medium uppercase tracking-wide text-slate-500`,children:(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Role`}),(0,h.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Permissions`}),(0,h.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Users`}),(0,h.jsx)(`th`,{scope:`col`,className:`px-4 py-3`,children:`Status`}),(0,h.jsx)(`th`,{scope:`col`,className:`px-4 py-3 text-right`,children:`Actions`})]})}),(0,h.jsx)(`tbody`,{className:`divide-y divide-slate-100`,children:t.map(t=>(0,h.jsxs)(`tr`,{className:`hover:bg-slate-50`,children:[(0,h.jsxs)(`td`,{className:`px-4 py-3`,children:[(0,h.jsx)(s,{to:`/app/settings/roles/${t.name}`,className:`font-medium text-slate-900 hover:text-brand-700`,children:t.label}),(0,h.jsx)(`p`,{className:`text-xs text-slate-500`,children:t.name})]}),(0,h.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:t.permissions_count??0}),(0,h.jsx)(`td`,{className:`px-4 py-3 text-slate-600`,children:t.users_count??0}),(0,h.jsx)(`td`,{className:`px-4 py-3`,children:(0,h.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,h.jsx)(c,{tone:t.is_active?`success`:`neutral`,children:t.is_active?`Active`:`Inactive`}),t.is_system&&(0,h.jsx)(c,{tone:`info`,children:`System`})]})}),(0,h.jsx)(`td`,{className:`px-4 py-3`,children:(0,h.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[e(`role.create`)&&(0,h.jsx)(a,{variant:`ghost`,onClick:()=>S(t.name,t.label),loading:v.isPending&&v.variables?.name===t.name,children:`Clone`}),e(`role.delete`)&&!t.is_system&&(t.users_count??0)===0&&(0,h.jsx)(a,{variant:`ghost`,className:`text-red-600 hover:bg-red-50`,onClick:()=>C(t.name),loading:y.isPending&&y.variables===t.name,children:`Delete`})]})})]},t.name))})]})})]})}export{g as default};