import{d as S,u as k,a as I,r as N,b as U,t as r,c as R,o as q,e as A,f as u,g as _,h as a,w as t,i as C,j as e,l as B,m as E,n as M,N as i,p as m,q as j,s as w,v as V,x as z,y as D}from"./index-a0da86f0.js";import{_ as F}from"./logo-a60c622a.js";import{I as c}from"./iconify-56cbf3ff.js";import{_ as J}from"./_plugin-vue_export-helper-c27b6911.js";const K={class:"signup-container"},L={class:"signup-card"},O={class:"signup-header"},T={class:"logo"},$=["alt"],G={class:"title"},H={class:"signup-footer"},Q=S({__name:"Signup",setup(W){const g=B(),f=k(),p=I(),v=N(),h=N(!1),o=U({username:"",password:"",confirmPassword:"",email:"",phoneNumber:""}),P=(d,s)=>s!==o.password?new Error(r("Passwords do not match")):!0,x={username:[{required:!0,message:r("Please enter username"),trigger:"blur"},{min:3,message:r("Username must be at least 3 characters"),trigger:"blur"}],password:[{required:!0,message:r("Please enter password"),trigger:"blur"},{min:6,message:r("Password must be at least 6 characters"),trigger:"blur"}],confirmPassword:[{required:!0,message:r("Please confirm password"),trigger:"blur"},{validator:P,trigger:"blur"}],email:[{validator:(d,s)=>s?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(s)?!0:new Error(r("Please enter a valid email address")):!0,trigger:"blur"}],phoneNumber:[{required:!0,message:r("Please enter phone number"),trigger:"blur"},{pattern:/^1[3-9]\d{9}$/,message:r("Please enter a valid phone number"),trigger:"blur"}]},b=async()=>{var d;try{await((d=v.value)==null?void 0:d.validate()),h.value=!0;const s=await D({username:o.username,password:o.password,email:o.email||void 0,phone_number:o.phoneNumber});if(s.success)if(f.success(r("Sign up successful")),s.user)p.user=s.user,p.isAuthenticated=!0,localStorage.setItem("jingrow_user",JSON.stringify(s.user)),localStorage.setItem("jingrow_authenticated","true"),g.push("/");else{const n=await p.login(o.username,o.password);n.success?g.push("/"):(f.warning(n.error||r("注册成功，但自动登录失败，请手动登录")),g.push("/login"))}else{const n=s.error||r("Sign up failed");console.error("注册失败:",n,s),f.error(n)}}catch(s){console.error("注册异常:",s),f.error(s.message||r("Sign up failed, please try again"))}finally{h.value=!1}},y=R(()=>localStorage.getItem("appName")||"Jingrow");return q(async()=>{await p.initAuth(),p.isLoggedIn&&g.push("/")}),(d,s)=>{const n=E("router-link");return M(),A("div",K,[u("div",L,[u("div",O,[u("div",T,[u("img",{src:F,alt:y.value,width:"48",height:"48"},null,8,$)]),u("h1",G,_(y.value),1)]),a(e(V),{ref_key:"formRef",ref:v,model:o,rules:x,size:"medium","show-label":!1,onKeyup:C(b,["enter"])},{default:t(()=>[a(e(i),{path:"username"},{default:t(()=>[a(e(m),{value:o.username,"onUpdate:value":s[0]||(s[0]=l=>o.username=l),placeholder:e(r)("Username"),"input-props":{autocomplete:"username"}},{prefix:t(()=>[a(e(c),{icon:"tabler:user"})]),_:1},8,["value","placeholder"])]),_:1}),a(e(i),{path:"password"},{default:t(()=>[a(e(m),{value:o.password,"onUpdate:value":s[1]||(s[1]=l=>o.password=l),type:"password",placeholder:e(r)("Password"),"input-props":{autocomplete:"new-password"},"show-password-on":"click"},{prefix:t(()=>[a(e(c),{icon:"tabler:lock"})]),_:1},8,["value","placeholder"])]),_:1}),a(e(i),{path:"confirmPassword"},{default:t(()=>[a(e(m),{value:o.confirmPassword,"onUpdate:value":s[2]||(s[2]=l=>o.confirmPassword=l),type:"password",placeholder:e(r)("Confirm Password"),"input-props":{autocomplete:"new-password"},"show-password-on":"click"},{prefix:t(()=>[a(e(c),{icon:"tabler:lock"})]),_:1},8,["value","placeholder"])]),_:1}),a(e(i),{path:"email"},{default:t(()=>[a(e(m),{value:o.email,"onUpdate:value":s[3]||(s[3]=l=>o.email=l),placeholder:e(r)("Email (Optional)"),"input-props":{autocomplete:"email",type:"email"}},{prefix:t(()=>[a(e(c),{icon:"tabler:mail"})]),_:1},8,["value","placeholder"])]),_:1}),a(e(i),{path:"phoneNumber"},{default:t(()=>[a(e(m),{value:o.phoneNumber,"onUpdate:value":s[4]||(s[4]=l=>o.phoneNumber=l),placeholder:e(r)("Phone Number"),"input-props":{autocomplete:"tel"}},{prefix:t(()=>[a(e(c),{icon:"tabler:phone"})]),_:1},8,["value","placeholder"])]),_:1}),a(e(i),null,{default:t(()=>[a(e(j),{type:"primary",size:"medium",block:"",loading:h.value,onClick:b,class:"brand-button"},{default:t(()=>[w(_(e(r)("Sign up")),1)]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"]),u("div",H,[a(e(z),{depth:"3"},{default:t(()=>[w(_(e(r)("Already have an account?"))+" ",1),a(n,{to:"/login",class:"login-link"},{default:t(()=>[w(_(e(r)("Login")),1)]),_:1})]),_:1})])])])}}});const se=J(Q,[["__scopeId","data-v-ae336766"]]);export{se as default};
