import{a as e}from"./rolldown-runtime-B0Z9INg1.js";import{$ as t}from"./vendor-charts-iXlq6Rne.js";import{_ as n,g as r}from"./vendor-react-Dzc9WstK.js";import{c as i}from"./api-CqQWIBIg.js";import{t as a}from"./arrow-left-BHEa0Gjf.js";import{t as o}from"./ModulePermissionsEditor-M7SjO9Oy.js";import{t as s}from"./pencil-BpO9_j3g.js";import{t as c}from"./trash-2-D01WN1hB.js";import{_ as l}from"./vendor-flow-IzlrcDx6.js";import{a as u,fn as d,i as f,sn as p}from"./index-HkVQGc9M.js";import{t as m}from"./Skeleton-BPr2yo9M.js";import{t as h}from"./RoleFormModal-BIL3p6Wp.js";import{t as g}from"./Breadcrumb-f9OtSkTx.js";var _=e(t(),1),v=l();function y(){let{roleId:e}=n(),t=r(),[l,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),{data:S,isLoading:C,refetch:w}=d(e,{skip:!e}),[T,{isLoading:E}]=p();return C?(0,v.jsxs)(`div`,{className:`space-y-6`,children:[(0,v.jsx)(m,{width:200,height:20}),(0,v.jsx)(m,{variant:`rect`,height:300})]}):S?(0,v.jsxs)(`div`,{children:[(0,v.jsx)(g,{items:[{label:`User Management`,href:`/admin/users`},{label:`Roles`,href:`/admin/users/roles`},{label:S.name}],className:`mb-2`}),(0,v.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,v.jsxs)(`div`,{children:[(0,v.jsx)(`h1`,{className:`text-[20px] font-bold text-[var(--color-text-primary)] tracking-[-0.02em] font-heading`,children:S.name}),(0,v.jsx)(`div`,{className:`mt-1.5 h-[3px] w-9 rounded-full bg-[var(--color-accent)]`})]}),(0,v.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,v.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>t(`/admin/users/roles`),className:`gap-1.5`,children:[(0,v.jsx)(a,{className:`w-3.5 h-3.5`}),`Back`]}),(0,v.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>y(!0),className:`gap-1.5`,children:[(0,v.jsx)(s,{className:`w-3.5 h-3.5`}),`Edit`]}),!S.is_system&&(0,v.jsxs)(f,{variant:`danger`,size:`sm`,onClick:()=>x(!0),className:`gap-1.5`,children:[(0,v.jsx)(c,{className:`w-3.5 h-3.5`}),`Delete`]})]})]}),(0,v.jsx)(o,{role:S,onUpdate:w}),l&&(0,v.jsx)(h,{role:S,onClose:()=>y(!1),onSuccess:()=>{y(!1)}}),b&&(0,v.jsx)(u,{isOpen:!0,onClose:()=>x(!1),title:`Delete Role`,description:`Are you sure you want to delete "${S.name}"?`,size:`sm`,footer:(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(f,{variant:`outline`,onClick:()=>x(!1),children:`Cancel`}),(0,v.jsx)(f,{variant:`danger`,onClick:async()=>{if(S)try{await T(S.id).unwrap(),i.success(`Role deleted`),t(`/admin/users/roles`)}catch(e){let t=e;i.error(t.data?.message||`Failed to delete role`)}},isLoading:E,children:`Delete Role`})]}),children:S.user_count>0?(0,v.jsxs)(`p`,{className:`text-[13px] text-[var(--color-error)]`,children:[`This role has `,(0,v.jsxs)(`strong`,{children:[S.user_count,` active user(s)`]}),`. Reassign them before deleting.`]}):(0,v.jsx)(`p`,{className:`text-[13px] text-[var(--color-text-secondary)]`,children:`All permission settings for this role will be permanently removed.`})})]}):null}export{y as default};