import{r as i,j as e,aH as p,aJ as j,aK as f,aL as g,aM as D,aO as y,q as b,aR as v,i as c}from"./index-Dh1NdHQs.js";const N=({role:a,open:m,onOpenChange:l,onSubmit:u})=>{const[r,o]=i.useState(!1),[s,t]=i.useState("");i.useEffect(()=>{a&&t(a.name)},[a]);const h=async n=>{if(n.preventDefault(),!(!s.trim()||!a)){o(!0);try{await u(a.id,{name:s.trim()}),l(!1)}catch(x){console.error("Failed to update role:",x)}finally{o(!1)}}},d=()=>{a&&t(a.name),l(!1)};return e.jsx(p,{open:m,onOpenChange:d,children:e.jsxs(j,{className:"sm:max-w-md",children:[e.jsxs(f,{children:[e.jsx(g,{children:"Edit Role"}),e.jsx(D,{children:"Update the role name"})]}),e.jsxs("form",{onSubmit:h,children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"role-name",children:"Role Name *"}),e.jsx(b,{id:"role-name",value:s,onChange:n=>t(n.target.value),placeholder:"Enter role name",required:!0})]})}),e.jsxs(v,{className:"mt-6",children:[e.jsx(c,{type:"button",variant:"outline",onClick:d,children:"Cancel"}),e.jsx(c,{type:"submit",disabled:r||!s.trim(),children:r?"Updating...":"Update Role"})]})]})]})})};export{N as default};
