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