import{et as e,i as t,r as n,st as r,ut as i}from"./branding-ClCX8iZg.js";import{t as a}from"./checkbox-BpeQUXEh.js";import{E as o}from"./index-CQbBgNYK.js";import{t as s}from"./HeaderApp-HWu4NOgP.js";import{t as c}from"./use-document-meta-Br4UMxjt.js";import{t as l}from"./api-toast-BFyXHsNH.js";import{t as u}from"./actions-HfS_qx7k.js";var d=i(r(),1),f=t();function p(){let t=e(),[r,i]=(0,d.useState)(``),[p,m]=(0,d.useState)(``),[h,g]=(0,d.useState)(``),[_,v]=(0,d.useState)(!1),[y,b]=(0,d.useState)(!1);c({title:`New User`,description:`Create a new user account.`});function x(){b(!0),l(u({email:r.trim(),username:p.trim(),password:h,is_admin:_}),{loading:`Creating user...`,success:`User created`,error:`Failed to create user`}).then(()=>t(`/users`)).catch(()=>{}).finally(()=>b(!1))}let S=r.trim().length>0&&p.trim().length>=3&&h.length>=8&&!y;return(0,f.jsx)(s,{title:`New User`,description:`Create a new user account.`,children:(0,f.jsxs)(`div`,{className:`max-w-lg space-y-6`,children:[(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`label`,{htmlFor:`user-email`,className:`text-sm font-medium`,children:`Email`}),(0,f.jsx)(o,{id:`user-email`,type:`email`,placeholder:`user@example.com`,value:r,onChange:e=>i(e.target.value),className:`mt-1`})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`label`,{htmlFor:`user-username`,className:`text-sm font-medium`,children:`Username`}),(0,f.jsx)(o,{id:`user-username`,placeholder:`johndoe`,value:p,onChange:e=>m(e.target.value),className:`mt-1`}),(0,f.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:`At least 3 characters`})]}),(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`label`,{htmlFor:`user-password`,className:`text-sm font-medium`,children:`Password`}),(0,f.jsx)(o,{id:`user-password`,type:`password`,placeholder:`Min. 8 characters`,value:h,onChange:e=>g(e.target.value),className:`mt-1`})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(a,{id:`user-is-admin`,checked:_,onCheckedChange:e=>v(e===!0)}),(0,f.jsx)(`label`,{htmlFor:`user-is-admin`,className:`text-sm font-medium cursor-pointer`,children:`Admin privileges`})]}),(0,f.jsxs)(`div`,{className:`flex gap-3`,children:[(0,f.jsx)(n,{variant:`outline`,onClick:()=>t(`/users`),children:`Cancel`}),(0,f.jsx)(n,{onClick:x,disabled:!S,children:y?`Creating...`:`Create User`})]})]})})}export{p as Component};