import{i as e}from"./chunk-aKtaBQYM.js";import{Rt as t,Vt as n,d as r,t as i,wt as a,zt as o}from"./mui-B6lh3XSP.js";import{l as s,t as c}from"./IconButton-BEBOUWhl.js";import{t as l}from"./TextField-DOdnjCrL.js";import{t as u}from"./Typography-DfQXhGTT.js";import{Mt as d,en as f,f as p,mt as m,pt as h,w as g,yt as _}from"./index-KVuxnkWj.js";import{t as v}from"./LoginLayout-D-6rL4KT.js";import{t as y}from"./BackIcon-BjuxlqVJ.js";var b=e(n(),1),x=a(),S=i()(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(),n=t(),i=s(),a=_(),C=o(e=>e.session.server),w=o(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);h(async({signal:e})=>{w&&M(await(await g(`/api/users/totp`,{method:`POST`,signal:e})).text())},[w,M]);let F=m(async e=>{e.preventDefault(),await g(`/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:()=>i(`/login`),children:(0,x.jsx)(y,{})}),(0,x.jsx)(u,{className:e.title,color:`primary`,children:a(`loginRegister`)})]}),(0,x.jsx)(l,{required:!0,label:a(`sharedName`),name:`name`,value:T,autoComplete:`name`,autoFocus:!0,onChange:e=>E(e.target.value)}),(0,x.jsx)(l,{required:!0,type:`email`,label:a(`userEmail`),name:`email`,value:D,autoComplete:`email`,onChange:e=>O(e.target.value)}),(0,x.jsx)(l,{required:!0,label:a(`userPassword`),name:`password`,value:k,type:`password`,autoComplete:`current-password`,onChange:e=>A(e.target.value)}),w&&(0,x.jsx)(l,{required:!0,label:a(`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:a(`loginRegister`)})]}),(0,x.jsx)(d,{open:N,onClose:()=>{n(r.updateServer({...C,newServer:!1})),i(`/login`)},autoHideDuration:p,message:a(`loginCreated`)})]})};export{C as default};