import{r as e}from"./rolldown-runtime-hePW80VL.js";import{o as t}from"./vendor-forms-yQg41KHz.js";import{l as n,t as r,u as i}from"./vendor-react-CAGJwf-T.js";import{c as a}from"./api-sqDSbqTC.js";import{t as o}from"./arrow-left-C4s0_GjY.js";import{t as s}from"./pencil-Bn2u6NKT.js";import{t as c}from"./trash-2-BeRwczU4.js";import{t as l}from"./users-CYR7ECMV.js";import{i as u,s as d}from"./usersRtkApi-CxqBEUpQ.js";import{D as f,O as p,S as m}from"./index-Z_bdWDpJ.js";import{t as h}from"./PageHeader-UI75nV23.js";import{t as g}from"./Skeleton-0UpX2lan.js";import{n as _,t as v}from"./Tabs-D8UstNBC.js";import{n as y,t as b}from"./Breadcrumb-BHdHGcrA.js";import{n as x,r as S,t as C}from"./FieldMaskEditor-BJtrbxKS.js";var w=e(t(),1),T=r(),E=[{id:`permissions`,label:`Module Permissions`},{id:`data-access`,label:`Data Access`},{id:`field-masks`,label:`Field Masking`}];function D(){let{roleId:e}=i(),t=n(),[r,D]=(0,w.useState)(!1),[O,k]=(0,w.useState)(!1),{data:A,isLoading:j}=d(e,{skip:!e}),[M,{isLoading:N}]=u();return j?(0,T.jsxs)(`div`,{className:`space-y-6`,children:[(0,T.jsx)(g,{width:200,height:20}),(0,T.jsx)(g,{variant:`rect`,height:300})]}):A?(0,T.jsxs)(`div`,{children:[(0,T.jsx)(b,{items:[{label:`User Management`,href:`/admin/users`},{label:`Roles`,href:`/admin/users/roles`},{label:A.name}],className:`mb-4`}),(0,T.jsx)(h,{title:A.name,description:A.description||`No description provided.`,actions:(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>t(`/admin/users/roles`),className:`gap-1.5`,children:[(0,T.jsx)(o,{className:`w-3.5 h-3.5`}),`Back`]}),(0,T.jsxs)(f,{variant:`outline`,size:`sm`,onClick:()=>D(!0),className:`gap-1.5`,children:[(0,T.jsx)(s,{className:`w-3.5 h-3.5`}),`Edit`]}),!A.is_system&&(0,T.jsxs)(f,{variant:`danger`,size:`sm`,onClick:()=>k(!0),className:`gap-1.5`,children:[(0,T.jsx)(c,{className:`w-3.5 h-3.5`}),`Delete`]})]})}),(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 mb-6`,children:[(0,T.jsx)(m,{variant:A.is_active?`success`:`error`,dot:!0,children:A.is_active?`Active`:`Inactive`}),A.is_system&&(0,T.jsx)(m,{variant:`warning`,dot:!0,children:`System Role`}),(0,T.jsxs)(m,{variant:`default`,children:[(0,T.jsx)(l,{className:`w-3 h-3 mr-1`}),A.user_count,` users`]})]}),(0,T.jsxs)(_,{tabs:E,defaultTab:`permissions`,children:[(0,T.jsx)(v,{id:`permissions`,children:(0,T.jsx)(S,{role:A,onUpdate:()=>{}})}),(0,T.jsx)(v,{id:`data-access`,children:(0,T.jsx)(x,{role:A,onUpdate:()=>{}})}),(0,T.jsx)(v,{id:`field-masks`,children:(0,T.jsx)(C,{role:A,onUpdate:()=>{}})})]}),r&&(0,T.jsx)(y,{role:A,onClose:()=>D(!1),onSuccess:()=>{D(!1)}}),O&&(0,T.jsx)(p,{isOpen:!0,onClose:()=>k(!1),title:`Delete Role`,description:`Are you sure you want to delete "${A.name}"?`,size:`sm`,footer:(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(f,{variant:`outline`,onClick:()=>k(!1),children:`Cancel`}),(0,T.jsx)(f,{variant:`danger`,onClick:async()=>{if(A)try{await M(A.id).unwrap(),a.success(`Role deleted`),t(`/admin/users/roles`)}catch(e){let t=e;a.error(t.data?.message||`Failed to delete role`)}},isLoading:N,children:`Delete Role`})]}),children:A.user_count>0?(0,T.jsxs)(`p`,{className:`text-[13px] text-[var(--color-error)]`,children:[`This role has `,(0,T.jsxs)(`strong`,{children:[A.user_count,` active user(s)`]}),`. Reassign them before deleting.`]}):(0,T.jsx)(`p`,{className:`text-[13px] text-[var(--color-text-secondary)]`,children:`All permission settings for this role will be permanently removed.`})})]}):null}export{D as default};