import{ai as F,q as j,bU as H,aD as U,aC as Y,Y as r,c as x,a,t as o,l as e,F as R,h as c,k as N,af as V,aq as g,i as $,j as K,aL as O,av as E,aM as A,ah as S,aN as q,o as P,bR as z,aA as G,bV as B}from"./DCf1rzTk.js";import{c as u}from"./II2dJyQq.js";import{_ as J}from"./BNwnZCQj.js";import{d as p}from"./BKvmybFC.js";const Q={class:"auth-form"},W={class:"iconified-input"},X={for:"email",hidden:""},Z=["placeholder"],ee=["disabled"],te={class:"iconified-input"},se={for:"password",hidden:""},ae=["placeholder"],oe={class:"iconified-input"},ie={for:"confirm-password",hidden:""},ne=["placeholder"],he={__name:"reset-password",async setup(le){let n,h;const{addNotification:m}=F(),{formatMessage:t}=j(),w=p({description:{id:"auth.reset-password.method-choice.description",defaultMessage:"Enter your email below and we'll send a recovery link to allow you to recover your account."},emailUsernameLabel:{id:"auth.reset-password.method-choice.email-username.label",defaultMessage:"Email or username"},emailUsernamePlaceholder:{id:"auth.reset-password.method-choice.email-username.placeholder",defaultMessage:"Email"},action:{id:"auth.reset-password.method-choice.action",defaultMessage:"Send recovery email"}}),y=p({description:{id:"auth.reset-password.post-challenge.description",defaultMessage:"Enter your new password below to gain access to your account."},confirmPasswordLabel:{id:"auth.reset-password.post-challenge.confirm-password.label",defaultMessage:"Confirm password"},action:{id:"auth.reset-password.post-challenge.action",defaultMessage:"Reset password"}}),k=p({title:{id:"auth.reset-password.notification.email-sent.title",defaultMessage:"Email sent"},text:{id:"auth.reset-password.notification.email-sent.text",defaultMessage:"An email with instructions has been sent to you if the email was previously saved on your account."}}),L=p({title:{id:"auth.reset-password.notification.password-reset.title",defaultMessage:"Password successfully reset"},text:{id:"auth.reset-password.notification.password-reset.text",defaultMessage:"You can now log-in into your account with your new password."}}),C=p({title:{id:"auth.reset-password.title",defaultMessage:"Reset Password"},longTitle:{id:"auth.reset-password.title.long",defaultMessage:"Reset your password"}});H({title:()=>`${t(C.title)} - Modrinth`}),([n,h]=U(()=>O()),n=await n,h(),n).value.user&&([n,h]=U(()=>E("/dashboard")),await n,h());const T=Y(),b=r("choose_method");T.query.flow&&(b.value="passed_challenge");const v=r(),f=r(""),d=r("");async function I(){var l;A();try{await S("auth/password/reset",{method:"POST",body:{username:f.value,challenge:d.value}}),m({title:t(k.title),text:t(k.text),type:"success"})}catch(s){m({title:t(u.errorNotificationTitle),text:s.data?s.data.description:s,type:"error"}),(l=v.value)==null||l.reset()}q()}const _=r(""),M=r("");async function D(){var l;A();try{await S("auth/password",{method:"PATCH",body:{new_password:_.value,flow:T.query.flow}}),m({title:t(L.title),text:t(L.text),type:"success"}),await E("/auth/sign-in")}catch(s){m({title:t(u.errorNotificationTitle),text:s.data?s.data.description:s,type:"error"}),(l=v.value)==null||l.reset()}q()}return(l,s)=>(P(),x("div",null,[a("h1",null,o(e(t)(e(C).longTitle)),1),a("section",Q,[e(b)==="choose_method"?(P(),x(R,{key:0},[a("p",null,o(e(t)(e(w).description)),1),a("div",W,[a("label",X,o(e(t)(e(w).emailUsernameLabel)),1),c(e(z)),N(a("input",{id:"email","onUpdate:modelValue":s[0]||(s[0]=i=>g(f)?f.value=i:null),type:"text",autocomplete:"username",class:"auth-form__input",placeholder:e(t)(e(w).emailUsernamePlaceholder)},null,8,Z),[[V,e(f)]])]),c(J,{ref_key:"captcha",ref:v,modelValue:e(d),"onUpdate:modelValue":s[1]||(s[1]=i=>g(d)?d.value=i:null)},null,8,["modelValue"]),a("button",{class:"btn btn-primary centered-btn",disabled:!e(d),onClick:I},[c(e(G)),$(" "+o(e(t)(e(w).action)),1)],8,ee)],64)):e(b)==="passed_challenge"?(P(),x(R,{key:1},[a("p",null,o(e(t)(e(y).description)),1),a("div",te,[a("label",se,o(e(t)(e(u).passwordLabel)),1),c(e(B)),N(a("input",{id:"password","onUpdate:modelValue":s[2]||(s[2]=i=>g(_)?_.value=i:null),type:"password",autocomplete:"new-password",class:"auth-form__input",placeholder:e(t)(e(u).passwordLabel)},null,8,ae),[[V,e(_)]])]),a("div",oe,[a("label",ie,o(e(t)(e(u).passwordLabel)),1),c(e(B)),N(a("input",{id:"confirm-password","onUpdate:modelValue":s[3]||(s[3]=i=>g(M)?M.value=i:null),type:"password",autocomplete:"new-password",class:"auth-form__input",placeholder:e(t)(e(y).confirmPasswordLabel)},null,8,ne),[[V,e(M)]])]),a("button",{class:"auth-form__input btn btn-primary continue-btn",onClick:D},o(e(t)(e(y).action)),1)],64)):K("",!0)])]))}};export{he as default};