import{an as w,ap as C,k as S,aD as I,l as U,r as u,bm as q,X as B,aA as z,b2 as M,g as O,al as G,a2 as F,j as e,T as o,a1 as L,am as k,a3 as m,L as h,B as f}from"./main-TIUJvpaR.js";import{A as N,G as W}from"./auth-layout-DWQg2Sxo.js";import{L as y}from"./external-link-DvqU4uvd.js";import{F as H}from"./checkbox-kZVscZNC.js";import{S as Q}from"./social-auth-section-jZCqz3zw.js";import"./CheckBoxOutlineBlank-p6gxL9Ym.js";import"./use-social-login-w6iLlymj.js";import"./use-all-social-logins-disabled-BoQ09ZS1.js";import"./envato-zsG_WUKe.js";import"./google-Dkq6mbpd.js";import"./dialog-footer-yCpPZGPO.js";function V(a){const t=T();return w({mutationFn:s=>S.post("auth/login",s).then(r=>r.data),onSuccess:s=>{s.two_factor||t(s)},onError:s=>C(s,a)})}function T(){const a=I(),{getRedirectUri:t}=U();return u.useCallback(s=>{var n,i;let r=((n=s.url)==null?void 0:n.intended)??t();if(r.includes("/oauth/"))window.location.href=r;else{q(s.bootstrapData),r=((i=s.url)==null?void 0:i.intended)??t();const c=r.replace(B().settings.base_url,"");a(c,{replace:!0})}},[a,t])}function X({onTwoFactorChallenge:a,bottomMessages:t}){var v;const[s]=z(),{pathname:r}=M(),n=r.includes("workspace"),i=s.get("email")||void 0,{branding:c,registration:d,site:P,social:g}=O(),p=!(d!=null&&d.disable),D=u.useContext(G),E=P.demo&&!i?K(D):{},l=F({defaultValues:{remember:!0,email:i,...E}}),j=V(l),R=n?e.jsx(o,{values:{siteName:c==null?void 0:c.site_name},message:"To join your team on :siteName, login to your account"}):e.jsx(o,{message:"Sign in to your account"}),_=(p||t)&&e.jsxs("div",{className:"space-y-8",children:[p&&e.jsx("div",{children:e.jsx(o,{message:"Don't have an account? <a>Sign up.</a>",values:{a:x=>e.jsx(h,{className:y,to:"/register",children:x})}})}),t]}),b=!!Object.keys(l.formState.errors).length;return e.jsxs(N,{heading:R,message:_,children:[e.jsx(L,{children:e.jsx(o,{message:"Login"})}),e.jsxs(k,{form:l,onSubmit:x=>{j.mutate(x,{onSuccess:A=>{A.two_factor&&a()}})},children:[e.jsx(m,{className:"mb-32",name:"email",type:"email",label:e.jsx(o,{message:"Email"}),disabled:!!i,invalid:b,errorMessage:((v=l.formState.errors.email)==null?void 0:v.message)&&e.jsx(J,{}),required:!0}),e.jsx(m,{className:"mb-12",name:"password",type:"password",label:e.jsx(o,{message:"Password"}),invalid:b,labelSuffix:e.jsx(h,{className:y,to:"/forgot-password",tabIndex:-1,children:e.jsx(o,{message:"Forgot your password?"})}),required:!0}),e.jsx(H,{name:"remember",className:"mb-32 block",children:e.jsx(o,{message:"Stay signed in for a month"})}),e.jsx(f,{className:"block w-full",type:"submit",variant:"flat",color:"primary",size:"md",disabled:j.isPending,children:e.jsx(o,{message:"Continue"})})]}),e.jsx(Q,{dividerMessage:g!=null&&g.compact_buttons?e.jsx(o,{message:"Or sign in with"}):e.jsx(o,{message:"OR"})})]})}function J(){return e.jsx(o,{message:"These credentials do not match our records. Try again or <a>get a new password</a>.",values:{a:a=>e.jsx(h,{className:"font-semibold underline",to:"/forgot-password",tabIndex:-1,children:a})}})}function K(a){var t,s;return{email:((t=a.demo)==null?void 0:t.email)??"admin@admin.com",password:((s=a.demo)==null?void 0:s.password)??"admin"}}function Y(a){const t=T();return w({mutationFn:s=>Z(s),onSuccess:s=>{t(s)},onError:s=>C(s,a)})}function Z(a){return S.post("auth/two-factor-challenge",a).then(t=>t.data)}function $(){const[a,t]=u.useState(!1),s=F(),r=Y(s);return e.jsxs(N,{children:[e.jsx(L,{children:e.jsx(o,{message:"Two factor authentication"})}),e.jsxs(k,{form:s,onSubmit:n=>{r.mutate(n)},children:[e.jsx("div",{className:"mb-32 text-sm",children:e.jsx(o,{message:"Confirm access to your account by entering the authentication code provided by your authenticator application."})}),e.jsx("div",{className:"mb-4",children:a?e.jsx(m,{name:"recovery_code",minLength:21,maxLength:21,autoComplete:"off",autoCorrect:"off",spellCheck:"false",label:e.jsx(o,{message:"Recovery code"}),autoFocus:!0,required:!0}):e.jsx(m,{name:"code",minLength:6,maxLength:6,autoComplete:"off",autoCorrect:"off",spellCheck:"false",label:e.jsx(o,{message:"Code"}),autoFocus:!0,required:!0})}),e.jsx("div",{className:"mb-32",children:e.jsx(f,{variant:"link",color:"primary",size:"sm",onClick:()=>t(!a),children:e.jsx(o,{message:"Use recovery code instead"})})}),e.jsx(f,{className:"block w-full",type:"submit",variant:"flat",color:"primary",size:"md",disabled:r.isPending,children:e.jsx(o,{message:"Continue"})})]})]})}function ue({bottomMessages:a}){const[t,s]=u.useState(!1),r=t?e.jsx($,{}):e.jsx(X,{onTwoFactorChallenge:()=>s(!0),bottomMessages:a});return e.jsx(W,{children:r})}export{ue as LoginPageWrapper};
