import{B as P}from"./Button-LyDQSUp0.js";import{a as z,_ as O}from"./GoogleAuth.vue_vue_type_script_setup_true_lang-CL1AtZaZ.js";import{d as Z,b3 as $,l as U,n as j,c as _,x as i,B as n,O as R,aj as u,w as B,aG as G,o as k,aZ as M,b2 as H,b1 as K,a_ as a}from"./index-BXlk60bP.js";import{S as W,a7 as c,$ as o,a1 as C,an as F,ap as J}from"./common-vYHpopNV.js";import{e as L}from"./index-Do_nuS4j.js";import"./_commonjsHelpers-BosuxZz1.js";const Q={class:"space-y-3 w-full",md:"w-lg!"},X={class:"w-full space-y-3"},Y={key:0,class:"text-sm"},ee={key:1,class:"text-sm text-dark"},te={class:"flex items-center space-x-3"},se={class:"text-sm font-bold text-dark-50 text-center"},de=Z({__name:"Reset",setup(oe){$("Register");function E(s){return s=s.trim(),/^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/.test(s)}const V=U(K),t=W({email:V.value,password:"",code:""});let p=c(!1);const g=c(!1);let r=j(()=>{if(!t.email)return null;const s=L.run({email:t.email});if(g.value=!1,s){const e=t.email.split("@")[1];return s.domain!=e?{originDomain:e,suggestedDomain:s.domain}:null}else return null});const N=()=>{r.value&&(t.email=t.email.replace(r.value.originDomain,r.value.suggestedDomain))},y=c(!1),x=c("SEND CODE");function T(){if(t.email==""){a({type:"error",message:"Can't send code without email."});return}else{E(t.email)?s():a({type:"error",message:"Incorrect email address."});return}function s(){y.value=!0,F({email:t.email}).then(e=>{const{code:v,msg:d}=e;if(v==200){let m=function(){f>0?(x.value=f--+"s RESEND",setTimeout(m,1e3)):(x.value="SEND CODE",p.value=!1)};p.value=!0;let f=60;m()}else a({type:"error",message:d})}).catch(()=>{a({type:"error",message:"Send failed, please check your network connection and try again."})}),y.value=!1}}const D=M(),w=c(!1);async function I(){if(t.email==""){a({type:"error",message:"Email is required."});return}else if(!E(t.email)){a({type:"error",message:"Incorrect email address."});return}if(t.password==""){a({type:"error",message:"Password is required."});return}w.value=!0;try{(await J(t)).code==200&&(V.value=t.email,D.push("/login"))}catch{}w.value=!1}const q=H();function A(){var s;D.push(((s=q.query)==null?void 0:s.next)||"/")}function h(s){}return(s,e)=>{var S,b;const v=z,d=O,m=P,f=G("router-link");return k(),_("div",Q,[i("div",X,[n(v,{onSuccess:A,onError:h}),e[9]||(e[9]=i("p",{text:"sm center"},"or",-1)),n(d,{modelValue:o(t).email,"onUpdate:modelValue":e[0]||(e[0]=l=>o(t).email=l),icon:"i-ant-design:mail-twotone text-blue-500",placeholder:"Email address",required:""},null,8,["modelValue"]),o(r)&&!o(g)?(k(),_("p",Y,[e[4]||(e[4]=u("Are you sure the domain name is ")),i("span",{class:"underline text-blue-500 cursor-pointer",onClick:e[1]||(e[1]=l=>g.value=!0)},C((S=o(r))==null?void 0:S.originDomain),1),e[5]||(e[5]=u(" and not ")),i("span",{class:"underline text-green-500 cursor-pointer",onClick:N},C((b=o(r))==null?void 0:b.suggestedDomain),1),e[6]||(e[6]=u("?"))])):R("",!0),o(p)?(k(),_("p",ee,"Code sent. If not received in 1 min, check email address.")):R("",!0),i("div",te,[n(d,{class:"w-2/3",modelValue:o(t).code,"onUpdate:modelValue":e[2]||(e[2]=l=>o(t).code=l),icon:"i-bi:send-check-fill text-green-500",placeholder:"Verification code sent to your email",required:""},null,8,["modelValue"]),n(m,{class:"max-w-1/3",type:"primary",size:"large",loading:o(y),onClick:T,disabled:o(p)},{default:B(()=>[u(C(o(x)),1)]),_:1},8,["loading","disabled"])]),n(d,{modelValue:o(t).password,"onUpdate:modelValue":e[3]||(e[3]=l=>o(t).password=l),icon:"i-ant-design:lock-twotone text-orange-500",placeholder:"New Password",required:""},null,8,["modelValue"]),n(m,{loading:o(w),onClick:I,type:"primary",icon:"i-fluent:key-reset-24-filled",text:"RESET PASSWORD"},null,8,["loading"]),i("p",se,[e[8]||(e[8]=u(" Have an account? ")),n(f,{to:"/login",class:"text-current underline underline-current"},{default:B(()=>e[7]||(e[7]=[u("Sign in now.")])),_:1})])])])}}});export{de as default};
