import{n as e}from"./rolldown-runtime-CbXtAM7H.js";import{a as t,o as n}from"./query-BtP_B6q9.js";import{c as r,n as i,s as a}from"./react-CdhQMFNz.js";import{A as o,C as s,_ as c,j as l}from"./vendor-B2maTQLc.js";import{_ as u,h as d,l as f,n as p}from"./Logo-CWvlQZMc.js";import{s as m}from"./main-DV3J5_jb.js";import{t as h}from"./AuthLayout-Cc_D8XEr.js";var g=e(n(),1),_=t();function v(){let{login:e}=m(),t=r(),n=a(),[v,y]=(0,g.useState)(``),[b,x]=(0,g.useState)(``),[S,C]=(0,g.useState)(!1),[w,T]=(0,g.useState)(!1),[E,D]=(0,g.useState)(!1),[O,k]=(0,g.useState)(!1),[A,j]=(0,g.useState)(``),[M,N]=(0,g.useState)(null),[P,F]=(0,g.useState)(!1);return(0,_.jsx)(h,{title:E?`Two-factor authentication`:`Sign in`,description:E?`Enter the six-digit code from your authenticator app.`:`Access your portfolio, offers and purchases.`,footer:E?(0,_.jsx)(`button`,{type:`button`,className:`text-text-accent underline underline-offset-4`,onClick:()=>{D(!1),j(``),k(!1),N(null)},children:`Use a different account`}):(0,_.jsxs)(_.Fragment,{children:[`New to Domainsansar?`,` `,(0,_.jsx)(i,{to:`/register`,className:`font-medium text-text-accent underline underline-offset-4`,children:`Create an account`})]}),children:(0,_.jsxs)(`form`,{onSubmit:async r=>{r.preventDefault(),N(null),F(!0);try{await e({email:v,password:b,remember:S,...E&&!O?{two_factor_code:A}:{},...E&&O?{recovery_code:A}:{}});let r=n.state?.from??`/dashboard`;t(r,{replace:!0})}catch(e){if(e instanceof p)e.twoFactorRequired?(D(!0),N(null)):N(e);else throw e}finally{F(!1)}},className:`flex flex-col gap-4`,noValidate:!0,children:[M!==null&&!M.isValidation&&(0,_.jsx)(u,{tone:`error`,title:M.isThrottled?`Too many attempts`:`Cannot sign in`,children:M.message}),E?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(f,{label:O?`Recovery code`:`Authentication code`,value:A,onChange:e=>j(e.target.value),autoComplete:`one-time-code`,inputMode:O?`text`:`numeric`,autoFocus:!0,required:!0,leadingIcon:(0,_.jsx)(s,{className:`size-4`}),error:M?.errorFor(`two_factor_code`)??M?.errorFor(`recovery_code`),hint:O?`Each recovery code works once.`:`Open your authenticator app to find the current code.`}),(0,_.jsx)(`button`,{type:`button`,className:`self-start text-sm text-text-accent underline underline-offset-4`,onClick:()=>{k(e=>!e),j(``)},children:O?`Use an authenticator code instead`:`Use a recovery code instead`})]}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(f,{label:`Email address`,type:`email`,value:v,onChange:e=>y(e.target.value),autoComplete:`email`,autoFocus:!0,required:!0,leadingIcon:(0,_.jsx)(c,{className:`size-4`}),error:M?.errorFor(`email`)}),(0,_.jsx)(f,{label:`Password`,type:w?`text`:`password`,value:b,onChange:e=>x(e.target.value),autoComplete:`current-password`,required:!0,error:M?.errorFor(`password`),trailingSlot:(0,_.jsx)(`button`,{type:`button`,onClick:()=>T(e=>!e),"aria-label":w?`Hide password`:`Show password`,className:`flex size-8 items-center justify-center rounded-md text-text-muted hover:text-text-primary`,children:w?(0,_.jsx)(l,{"aria-hidden":!0,className:`size-4`}):(0,_.jsx)(o,{"aria-hidden":!0,className:`size-4`})})}),(0,_.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,_.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-text-secondary`,children:[(0,_.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`size-4 rounded border-border-control accent-[var(--accent-solid)]`}),`Keep me signed in`]}),(0,_.jsx)(i,{to:`/forgot-password`,className:`text-sm text-text-accent underline underline-offset-4`,children:`Forgot password?`})]})]}),(0,_.jsx)(d,{type:`submit`,size:`lg`,fullWidth:!0,isLoading:P,children:E?`Verify and sign in`:`Sign in`})]})})}export{v as LoginPage};
//# sourceMappingURL=LoginPage-BajWadMq.js.map