import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{$ as t}from"./vendor-charts-iXlq6Rne.js";import{g as n}from"./vendor-react-Dzc9WstK.js";import{t as r}from"./DataTable-Dc5x7VxX.js";import{t as i}from"./arrow-right-BvVjz62x.js";import{t as a}from"./plus-BV0zuql8.js";import{t as o}from"./shield-yDd--7Il.js";import{_ as s}from"./vendor-flow-IzlrcDx6.js";import{t as c}from"./format-2_0n0Bue.js";import{i as l,mn as u,wn as d}from"./index-HkVQGc9M.js";import{t as f}from"./Badge-Cw8tCXX7.js";import{r as p}from"./vendor-table-C04d_sgN.js";import{t as m}from"./PageHeader-D7FASfZI.js";import{t as h}from"./Tooltip-DX-zz9zg.js";import{t as g}from"./RoleFormModal-BIL3p6Wp.js";import{t as _}from"./Breadcrumb-f9OtSkTx.js";var v=e(t(),1),y=s(),b=p();function x(){let e=n(),[t,s]=(0,v.useState)(1),[p,x]=(0,v.useState)(20),[S,C]=(0,v.useState)(``),[w,T]=(0,v.useState)(!1),E=(0,v.useMemo)(()=>{let e={page:String(t),page_size:String(p)};return S&&(e.search=S),e},[t,p,S]),{data:D,isLoading:O,isFetching:k}=u(E),A=D?.results??[],j=D?.count??0,M=(0,v.useMemo)(()=>[b.accessor(`name`,{header:`Role`,cell:e=>(0,y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,y.jsx)(`div`,{className:`w-9 h-9 rounded-lg bg-slate-100 dark:bg-slate-800 flex items-center justify-center flex-shrink-0`,children:(0,y.jsx)(o,{className:`w-4 h-4 text-[var(--color-text-muted)]`})}),(0,y.jsxs)(`div`,{className:`min-w-0`,children:[(0,y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`p`,{className:`text-[13px] font-medium text-[var(--color-text-primary)] truncate`,children:e.getValue()}),e.row.original.is_system&&(0,y.jsx)(f,{variant:`warning`,size:`sm`,children:`System`})]}),e.row.original.description&&(0,y.jsx)(`p`,{className:`text-[11px] text-[var(--color-text-muted)] truncate max-w-[300px] mt-px`,children:e.row.original.description})]})]})}),b.accessor(`user_count`,{header:`Users`,cell:e=>(0,y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,y.jsx)(d,{className:`w-3.5 h-3.5 text-[var(--color-text-muted)]`}),(0,y.jsx)(`span`,{className:`text-[13px] text-[var(--color-text-secondary)] tabular-nums`,children:e.getValue()})]})}),b.accessor(`is_active`,{header:`Status`,cell:e=>(0,y.jsx)(f,{variant:e.getValue()?`success`:`error`,size:`sm`,dot:!0,children:e.getValue()?`Active`:`Inactive`})}),b.accessor(`created_at`,{header:`Created`,cell:e=>{let t=e.getValue();return t?(0,y.jsx)(`span`,{className:`text-[12px] text-[var(--color-text-muted)] tabular-nums`,children:c(new Date(t),`dd MMM yyyy`)}):(0,y.jsx)(`span`,{className:`text-[12px] text-[var(--color-text-muted)]`,children:`—`})}}),b.display({id:`actions`,header:``,cell:t=>(0,y.jsx)(h,{content:`Configure permissions`,children:(0,y.jsx)(`button`,{"aria-label":`Configure permissions`,onClick:()=>e(`/admin/users/roles/${t.row.original.id}`),className:`p-1.5 rounded-md text-[var(--color-text-muted)] hover:bg-slate-100 dark:hover:bg-slate-700 hover:text-[var(--color-primary)] transition-colors`,children:(0,y.jsx)(i,{className:`w-4 h-4`})})})})],[e]);return(0,y.jsxs)(`div`,{children:[(0,y.jsx)(_,{items:[{label:`User Management`,href:`/admin/users`},{label:`Roles & Permissions`}],className:`mb-4`}),(0,y.jsx)(m,{title:`Roles & Permissions`,description:`Define roles and configure what each role can access across the platform.`,actions:(0,y.jsxs)(l,{onClick:()=>T(!0),className:`gap-1.5`,children:[(0,y.jsx)(a,{className:`w-4 h-4`}),`Create Role`]})}),(0,y.jsx)(r,{columns:M,data:A,isLoading:O,isFetching:k,searchPlaceholder:`Search roles...`,totalItems:j,currentPage:t,pageSize:p,totalPages:Math.ceil(j/p),onPageChange:s,onPageSizeChange:e=>{x(e),s(1)},onSearch:e=>{C(e),s(1)},emptyTitle:`No roles defined`,emptyDescription:`Create roles to control what admin users can do.`,emptyActionLabel:`Create Role`,onEmptyAction:()=>T(!0)}),w&&(0,y.jsx)(g,{onClose:()=>T(!1),onSuccess:()=>{T(!1)}})]})}export{x as default};