import{i as e}from"./chunk-aKtaBQYM.js";import{Ft as t,Mt as n,Nt as r,d as i,t as a,vt as o}from"./mui-BgU4WrXF.js";import{l as s,t as c}from"./IconButton-oialqkv3.js";import{t as l}from"./Typography-7EcQ2i3p.js";import{t as u}from"./TextField-DctlzLY-.js";import{Et as d,Ut as f,ct as p,f as m,pt as h,st as g,w as _}from"./index-bel1r0Sr.js";import{t as v}from"./LoginLayout-DF1i1Q4g.js";import{t as y}from"./BackIcon-CSBDQ_HZ.js";var b=e(t(),1),x=o(),S=a()(e=>({container:{display:`flex`,flexDirection:`column`,gap:e.spacing(2)},header:{display:`flex`,alignItems:`center`},title:{fontSize:e.spacing(3),fontWeight:500,marginLeft:e.spacing(1),textTransform:`uppercase`}})),C=()=>{let{classes:e}=S(),t=n(),a=s(),o=h(),C=r(e=>e.session.server),w=r(e=>e.session.server.attributes.totpForce),[T,E]=(0,b.useState)(``),[D,O]=(0,b.useState)(``),[k,A]=(0,b.useState)(``),[j,M]=(0,b.useState)(null),[N,P]=(0,b.useState)(!1);g(async({signal:e})=>{w&&M(await(await _(`/api/users/totp`,{method:`POST`,signal:e})).text())},[w,M]);let F=p(async e=>{e.preventDefault(),await _(`/api/users`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:T,email:D,password:k,totpKey:j})}),P(!0)});return(0,x.jsxs)(v,{children:[(0,x.jsxs)(`div`,{className:e.container,children:[(0,x.jsxs)(`div`,{className:e.header,children:[!C.newServer&&(0,x.jsx)(c,{color:`primary`,onClick:()=>a(`/login`),children:(0,x.jsx)(y,{})}),(0,x.jsx)(l,{className:e.title,color:`primary`,children:o(`loginRegister`)})]}),(0,x.jsx)(u,{required:!0,label:o(`sharedName`),name:`name`,value:T,autoComplete:`name`,autoFocus:!0,onChange:e=>E(e.target.value)}),(0,x.jsx)(u,{required:!0,type:`email`,label:o(`userEmail`),name:`email`,value:D,autoComplete:`email`,onChange:e=>O(e.target.value)}),(0,x.jsx)(u,{required:!0,label:o(`userPassword`),name:`password`,value:k,type:`password`,autoComplete:`current-password`,onChange:e=>A(e.target.value)}),w&&(0,x.jsx)(u,{required:!0,label:o(`loginTotpKey`),name:`totpKey`,value:j||``,slotProps:{input:{readOnly:!0}}}),(0,x.jsx)(f,{variant:`contained`,color:`secondary`,onClick:F,type:`submit`,disabled:!T||!k||!(C.newServer||/(.+)@(.+)\.(.{2,})/.test(D)),fullWidth:!0,children:o(`loginRegister`)})]}),(0,x.jsx)(d,{open:N,onClose:()=>{t(i.updateServer({...C,newServer:!1})),a(`/login`)},autoHideDuration:m,message:o(`loginCreated`)})]})};export{C as default};