import{ai as K,q as Q,bU as Y,aD as C,aC as j,Y as u,l as e,c as I,a,F as N,t as c,k as U,af as F,aq as L,bx as z,i as D,h as o,w as S,aL as B,aM as G,ah as R,aN as $,bW as X,av as q,o as m,V as A,bX as g,bY as Z,bZ as J,b_ as ee,b$ as te,c0 as ae,c1 as se,bQ as oe,bV as ne,g as E,s as W,bS as ie,Q as le}from"./Co0rzPff.js";import{c as M}from"./DcFkmsmp.js";import{_ as re}from"./Dgi-XuPz.js";import{d as de}from"./BKvmybFC.js";import{a as ce}from"./fCBWAsuZ.js";const ue={key:0},pe=["src"],fe={key:1},he={for:"two-factor-code"},me={class:"label__title"},ge={class:"label__description"},be=["placeholder"],_e={class:"third-party"},we=["href"],ye=["href"],ve=["href"],Ie=["href"],Le=["href"],Se=["href"],Me={class:"auth-form"},ke={class:"iconified-input"},xe={for:"email",hidden:""},Ce=["placeholder"],Ue={class:"iconified-input"},Fe={for:"password",hidden:""},qe=["placeholder"],Ve=["disabled"],Oe={class:"auth-form__additional-options"},Re={__name:"sign-in",async setup(Pe){let d,p;const{addNotification:V}=K(),{formatMessage:s}=Q(),l=de({additionalOptionsLabel:{id:"auth.sign-in.additional-options",defaultMessage:"Forgot password? • Create an account"},emailUsernameLabel:{id:"auth.sign-in.email-username.label",defaultMessage:"Email or username"},passwordLabel:{id:"auth.sign-in.password.label",defaultMessage:"Password"},signInWithLabel:{id:"auth.sign-in.sign-in-with",defaultMessage:"Sign in with"},signInTitle:{id:"auth.sign-in.title",defaultMessage:"Sign In"},twoFactorCodeInputPlaceholder:{id:"auth.sign-in.2fa.placeholder",defaultMessage:"Enter code..."},twoFactorCodeLabel:{id:"auth.sign-in.2fa.label",defaultMessage:"Enter two-factor code"},twoFactorCodeLabelDescription:{id:"auth.sign-in.2fa.description",defaultMessage:"Please enter a two-factor code to proceed."},usePasswordLabel:{id:"auth.sign-in.use-password",defaultMessage:"Or use a password"}});Y({title(){return`${s(l.signInTitle)} - Modrinth`}});const O=([d,p]=C(()=>B()),d=await d,p(),d),r=j(),f=r.query.redirect||"",_=u();r.query.code&&!r.fullPath.includes("new_account=true")&&([d,p]=C(()=>v()),await d,p()),O.value.user&&([d,p]=C(()=>v()),await d,p());const k=u(),w=u(""),y=u(""),b=u(""),x=u(r.query.flow);async function H(){var n;G();try{const t=await R("auth/login",{method:"POST",body:{username:w.value,password:y.value,challenge:b.value}});t.flow?x.value=t.flow:await v(t.session)}catch(t){V({title:s(M.errorNotificationTitle),text:t.data?t.data.description:t,type:"error"}),(n=k.value)==null||n.reset()}$()}const h=u(null);async function P(){var n;G();try{const t=await R("auth/login/2fa",{method:"POST",body:{flow:x.value,code:h.value?h.value.toString():h.value}});await v(t.session)}catch(t){V({title:s(M.errorNotificationTitle),text:t.data?t.data.description:t,type:"error"}),(n=k.value)==null||n.reset()}$()}async function v(n){if(r.query.launcher){n||(n=O.value.token);const t=`${X(r)}/?code=${n}`;t.startsWith("https://launcher-files.modrinth.com/")?await q(t,{external:!0}):_.value=t;return}if(n&&(await B(n),await ce()),r.query.redirect){const t=decodeURIComponent(r.query.redirect);await q(t,{replace:!0})}else await q("/dashboard")}return(n,t)=>{const T=le;return e(_)?(m(),I("div",ue,[a("iframe",{src:e(_),class:"fixed left-0 top-0 z-[9999] m-0 h-full w-full border-0 p-0"},null,8,pe)])):(m(),I("div",fe,[e(x)&&!e(_)?(m(),I(N,{key:0},[a("label",he,[a("span",me,c(e(s)(e(l).twoFactorCodeLabel)),1),a("span",ge,c(e(s)(e(l).twoFactorCodeLabelDescription)),1)]),U(a("input",{id:"two-factor-code","onUpdate:modelValue":t[0]||(t[0]=i=>L(h)?h.value=i:null),maxlength:"11",type:"text",placeholder:e(s)(e(l).twoFactorCodeInputPlaceholder),autocomplete:"one-time-code",autofocus:"",onKeyup:z(P,["enter"])},null,40,be),[[F,e(h)]]),a("button",{class:"btn btn-primary continue-btn",onClick:P},[D(c(e(s)(e(M).signInButton))+" ",1),o(e(A))])],64)):(m(),I(N,{key:1},[a("h1",null,c(e(s)(e(l).signInWithLabel)),1),a("section",_e,[a("a",{class:"btn",href:e(g)("discord",e(f))},[o(e(Z)),t[5]||(t[5]=a("span",null,"Discord",-1))],8,we),a("a",{class:"btn",href:e(g)("github",e(f))},[o(e(J)),t[6]||(t[6]=a("span",null,"GitHub",-1))],8,ye),a("a",{class:"btn",href:e(g)("microsoft",e(f))},[o(e(ee)),t[7]||(t[7]=a("span",null,"Microsoft",-1))],8,ve),a("a",{class:"btn",href:e(g)("google",e(f))},[o(e(te)),t[8]||(t[8]=a("span",null,"Google",-1))],8,Ie),a("a",{class:"btn",href:e(g)("steam",e(f))},[o(e(ae)),t[9]||(t[9]=a("span",null,"Steam",-1))],8,Le),a("a",{class:"btn",href:e(g)("gitlab",e(f))},[o(e(se)),t[10]||(t[10]=a("span",null,"GitLab",-1))],8,Se)]),a("h1",null,c(e(s)(e(l).usePasswordLabel)),1),a("section",Me,[a("div",ke,[a("label",xe,c(e(s)(e(l).emailUsernameLabel)),1),o(e(oe)),U(a("input",{id:"email","onUpdate:modelValue":t[1]||(t[1]=i=>L(w)?w.value=i:null),type:"text",autocomplete:"username",class:"auth-form__input",placeholder:e(s)(e(l).emailUsernameLabel)},null,8,Ce),[[F,e(w)]])]),a("div",Ue,[a("label",Fe,c(e(s)(e(l).passwordLabel)),1),o(e(ne)),U(a("input",{id:"password","onUpdate:modelValue":t[2]||(t[2]=i=>L(y)?y.value=i:null),type:"password",autocomplete:"current-password",class:"auth-form__input",placeholder:e(s)(e(l).passwordLabel)},null,8,qe),[[F,e(y)]])]),o(re,{ref_key:"captcha",ref:k,modelValue:e(b),"onUpdate:modelValue":t[3]||(t[3]=i=>L(b)?b.value=i:null)},null,8,["modelValue"]),a("button",{class:"btn btn-primary continue-btn centered-btn",disabled:!e(b),onClick:t[4]||(t[4]=i=>H())},[D(c(e(s)(e(M).signInButton))+" ",1),o(e(A))],8,Ve),a("div",Oe,[o(e(ie),{"message-id":e(l).additionalOptionsLabel},{"forgot-password-link":S(({children:i})=>[o(T,{class:"text-link",to:{path:"/auth/reset-password",query:e(r).query}},{default:S(()=>[(m(),E(W(()=>i)))]),_:2},1032,["to"])]),"create-account-link":S(({children:i})=>[o(T,{class:"text-link",to:{path:"/auth/sign-up",query:e(r).query}},{default:S(()=>[(m(),E(W(()=>i)))]),_:2},1032,["to"])]),_:1},8,["message-id"])])])],64))]))}}};export{Re as default};