import{j as e,r as o}from"./vendor-react-wBh_31cN.js";import{G as x,r as C,ar as O,av as S,au as P,as as q}from"./index-BKr2rJhV.js";import{u as F}from"./index.esm-CAGtek53.js";import{o as I}from"./yup-XkUC3UEH.js";import{j as Q,u as k}from"./vendor-redux-CJZrIb6x.js";import{I as n}from"./input-H6_qmzms.js";import{L as m}from"./label-Dnebucx5.js";import{C as u,a as h,b as p,c as f}from"./card-DISTA6Ay.js";import{H as A}from"./Hero-ILcN0sPk.js";import{L as z}from"./LoginHelp-o3t9pY65.js";import{C as G}from"./ConfirmQrCode-Bgw2jcqz.js";import{u as $}from"./vendor-router-D1GqFWiT.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./theme-colors-BFneJNsI.js";import"./getHopsDoc-BWSxyuXn.js";const B=({onClick:r})=>e.jsxs("div",{className:"flex flex-col items-center mt-[50px]",children:[e.jsx(A,{}),e.jsx("span",{className:"mb-[60px] mt-[15px] text-lg text-quartz-primary",children:"Hopsworks"}),e.jsxs(u,{className:"w-[466px]",children:[e.jsx(h,{children:e.jsx(p,{children:"Waiting for validation"})}),e.jsxs(f,{className:"flex flex-col",children:[e.jsx("span",{className:"text-sm font-semibold",children:"Account created"}),e.jsx("span",{className:"text-xs mt-2 mb-[15px]",children:"Your account is created. A cluster admin must validate your account before you can log in."}),e.jsx(x,{variant:"secondary",className:"self-end",onClick:r,children:"Login"})]})]})]}),D=({qrCode:r,otp:i,setOtp:j,isLoading:a,onSubmit:l})=>e.jsxs(u,{className:"w-[466px]",children:[e.jsx(h,{children:e.jsx(p,{children:"Add second factor authentication"})}),e.jsxs(f,{children:[e.jsx(G,{isLoading:a,qrCode:r,otp:i,setOtp:j,mainText:`TOTP 2-factor-authentification is set up as mandatory. If you
                don't have an "Authenticator App" (Authy, andOTP, Google
                Authenticator, ...) download one on your phone. Then add this
                Hopsworks account to set up your device as second factor
                authenticator.`,secondaryText:`Once the application is registered in your Authenticator App,
                generate a code and add it below to validate it.`}),e.jsx("div",{className:"flex justify-end mt-5",children:e.jsx(x,{onClick:l,children:"Register"})})]})]}),J=O().shape({email:q().email().required().label("Email"),password:P.label("Password"),firstName:S.label("First name"),lastName:S.label("Last name")}),ne=()=>{const r=$(),i=Q(),j=k(t=>t.auth),{formState:{errors:a},register:l,handleSubmit:g,watch:U}=F({shouldUnregister:!1,resolver:I(J)}),[v,d]=o.useState(null),[T,b]=o.useState(!1),[L,w]=o.useState(!1),[N,R]=o.useState(""),c=k(t=>t.loading.effects.auth.register),E=o.useCallback(async t=>{var y;d(null);const s=await i.auth.register({data:t});s!=null&&s.error&&(s==null?void 0:s.message)==="Network Error"||(s!=null&&s.error?d(s):s.data&&((y=s.data.data)!=null&&y.QRCode)?w(!0):b(!0))},[i.auth]),H=o.useCallback(async t=>{d(null);const s=await i.auth.validateOTP({email:t.email,password:t.password,otp:N});s!=null&&s.error&&(s==null?void 0:s.message)==="Network Error"||(s!=null&&s.error?d(s):(w(!1),b(!0)))},[i.auth,N]);return T?e.jsx(B,{onClick:()=>r(C.auth.login)}):e.jsxs("div",{className:"flex flex-col items-center mt-[50px]",children:[e.jsx(A,{}),e.jsx("span",{className:"mb-[60px] mt-[15px] text-lg text-quartz-primary",children:"Hopsworks"}),v&&e.jsx("div",{className:"w-[466px] mb-5 rounded-md border border-destructive bg-destructive/10 p-3 text-sm text-destructive",children:v.message}),L?e.jsx(D,{qrCode:j.qrCode,otp:N,setOtp:R,isLoading:c,onSubmit:g(H)}):e.jsxs(u,{className:"w-[466px] mb-5",children:[e.jsx(h,{children:e.jsx(p,{children:"Register"})}),e.jsxs(f,{className:"flex flex-col",children:[e.jsxs("div",{className:"flex gap-5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(m,{className:"mb-1.5",children:"First name"}),e.jsx(n,{...l("firstName"),disabled:c,placeholder:"John","aria-invalid":!!a.firstName}),a.firstName&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:a.firstName.message})]}),e.jsxs("div",{className:"flex-1",children:[e.jsx(m,{className:"mb-1.5",children:"Last name"}),e.jsx(n,{...l("lastName"),disabled:c,placeholder:"Tukey","aria-invalid":!!a.lastName}),a.lastName&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:a.lastName.message})]})]}),e.jsxs("div",{className:"w-full mt-5",children:[e.jsx(m,{className:"mb-1.5",children:"Email Address"}),e.jsx(n,{...l("email"),disabled:c,placeholder:"john@tukey.com","aria-invalid":!!a.email}),a.email&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:a.email.message})]}),e.jsxs("div",{className:"w-full mt-5",children:[e.jsx(m,{className:"mb-1.5",children:"Password"}),e.jsx(n,{type:"password",disabled:c,placeholder:"•••••••",...l("password"),"aria-invalid":!!a.password}),a.password&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:a.password.message})]}),e.jsx(x,{type:"submit",className:"self-end mt-5",onClick:g(E),disabled:c,children:"Register"})]})]}),e.jsxs(u,{className:"w-[466px] mb-5",children:[e.jsx(h,{className:"py-3",children:e.jsx(p,{className:"text-xs",children:"Already have an account?"})}),e.jsx(f,{className:"pt-0",children:e.jsx(x,{variant:"secondary",onClick:()=>r(C.auth.login),children:"Login"})})]}),e.jsx(z,{})]})};export{ne as default,J as schema};
