import{r as e}from"./rolldown-runtime-hePW80VL.js";import{o as t}from"./vendor-forms-yQg41KHz.js";import{r as n,t as r}from"./vendor-react-CAGJwf-T.js";import{c as i}from"./api-sqDSbqTC.js";import{t as a}from"./chevron-right-Cd4JszIi.js";import{t as o}from"./utils-Dk_44zMo.js";import{m as s,n as c}from"./usersRtkApi-CxqBEUpQ.js";import{C as l,D as u,O as d,T as f}from"./index-Z_bdWDpJ.js";import{t as p}from"./Toggle-DY9BCnV7.js";var m=e(t(),1),h=r();function g({role:e,onClose:t,onSuccess:n}){let r=!!e,[a,o]=(0,m.useState)(e?.name||``),[g,_]=(0,m.useState)(e?.description||``),[v,y]=(0,m.useState)(e?.is_active??!0),[b,x]=(0,m.useState)({}),[S,{isLoading:C}]=c(),[w,{isLoading:T}]=s(),E=C||T;return(0,h.jsx)(d,{isOpen:!0,onClose:t,title:r?`Edit Role`:`Create New Role`,description:r?`Update role name and description.`:`Define a new role. You can configure permissions after creation.`,size:`md`,footer:(0,h.jsxs)(h.Fragment,{children:[(0,h.jsx)(u,{variant:`outline`,onClick:t,children:`Cancel`}),(0,h.jsx)(u,{onClick:async()=>{if(!a.trim()){x({name:`Role name is required.`});return}try{r&&e?(await w({id:e.id,body:{name:a.trim(),description:g.trim(),is_active:v}}).unwrap(),i.success(`Role updated`)):(await S({name:a.trim(),description:g.trim(),is_active:v}).unwrap(),i.success(`Role created`)),n()}catch(e){let t=e.data?.errors;if(t){let e={};for(let[n,r]of Object.entries(t))Array.isArray(r)&&(e[n]=r[0]);x(e)}else i.error(r?`Failed to update role`:`Failed to create role`)}},isLoading:E,children:r?`Save Changes`:`Create Role`})]}),children:(0,h.jsxs)(`div`,{className:`space-y-4`,children:[(0,h.jsx)(f,{label:`Role Name`,value:a,onChange:e=>{o(e.target.value),x({})},placeholder:`e.g., Sales Manager`,error:b.name,disabled:e?.is_system,hint:e?.is_system?`System role names cannot be changed.`:void 0}),(0,h.jsx)(l,{label:`Description`,value:g,onChange:e=>_(e.target.value),placeholder:`Describe what this role is for...`,rows:3}),(0,h.jsx)(p,{checked:v,onChange:y,label:`Active`,description:`Inactive roles cannot be assigned to users.`})]})})}function _({items:e,className:t}){return(0,h.jsx)(`nav`,{"aria-label":`Breadcrumb`,className:o(`flex items-center text-sm`,t),children:(0,h.jsx)(`ol`,{className:`flex items-center gap-1.5`,children:e.map((t,r)=>{let i=r===e.length-1;return(0,h.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[r>0&&(0,h.jsx)(a,{className:`w-3.5 h-3.5 text-[var(--color-text-muted)] flex-shrink-0`}),i||!t.href?(0,h.jsx)(`span`,{className:o(`font-medium`,i?`text-[var(--color-text-primary)]`:`text-[var(--color-text-muted)]`),children:t.label}):(0,h.jsx)(n,{to:t.href,className:`text-[var(--color-text-muted)] hover:text-[var(--color-primary)] transition-colors duration-[var(--transition-fast)]`,children:t.label})]},r)})})})}export{g as n,_ as t};