import{h as N,e as L,u as U,B as q,D as M,E as c,H as O,W as H,c as a,o as i,a as r,I as k,t as s,g as t,d as f,b as $,w as C,J as w,L as Y,$ as j,a0 as J,X as Q,O as V,Q as u,P as F}from"./BzhixHsn.js";import{s as P}from"./D-0Ld2CH.js";const W={class:"flex flex-col gap-6"},X={class:"flex flex-col items-center gap-2 text-center"},z={class:"text-2xl font-bold"},G={class:"text-muted-foreground text-sm text-balance"},K={key:0},Z={key:1},ee={key:2},te={key:0,class:"rounded-md border border-green-200 bg-green-50 p-3 text-sm text-green-600"},se={class:"mt-2 text-xs"},ae={key:1,class:"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-600"},ie={key:2,class:"flex justify-center py-4"},ne={key:3,class:"space-y-4"},oe={class:"text-center"},re={class:"text-muted-foreground text-sm"},le={key:0,class:"space-y-2"},de={class:"text-muted-foreground text-center text-xs"},ce={key:1,class:"space-y-2"},ue={class:"space-y-2"},fe=["placeholder"],me={class:"text-muted-foreground text-center text-xs"},Ee=N({__name:"verify-email",setup(ve){const{t:n}=L();U({title:n("pageTitle.verifyEmail")});const T=q(),{$api:I}=M(),l=c(T.query.email||""),E=c(T.query.token||""),m=c(!1),_=c(""),x=c(""),h=c(!1),d=c(0);let v=null;const g=c(0);let y=null;const A=()=>{d.value=60,v=P(()=>{d.value--,d.value<=0&&(clearInterval(v),v=null)},1e3)},R=()=>{g.value=3,y=P(()=>{g.value--,g.value<=0&&(clearInterval(y),y=null,V("/sign-in"))},1e3)},B=async()=>{if(!E.value){u.error(n("verifyEmail.invalidLink"));return}m.value=!0;try{await I("/v1/auth/verify",{method:"POST",body:{token:E.value}}),_.value=n("verifyEmail.success"),R()}catch(e){if(!(e instanceof F))throw e;e.statusCode===400&&e.data?.detail==="VERIFY_USER_ALREADY_VERIFIED"?(_.value=n("verifyEmail.alreadyVerified"),R()):x.value=n("verifyEmail.failed")}finally{m.value=!1}},S=async()=>{if(!l.value){u.error(n("verifyEmail.missingEmail"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(l.value)){u.error(n("verifyEmail.invalidEmailFormat"));return}h.value=!0;try{await I("/v1/auth/request-verify-token",{method:"POST",body:{email:l.value}}),u.success(n("verifyEmail.resendSuccess")),A()}catch(o){if(o instanceof F)if(o.statusCode===429){const p=(o.data?.detail||"").match(/(\d+)\s*seconds?/),D=p?p[1]:"60";u.error(n("verifyEmail.rateLimitError",{seconds:D}))}else u.error(o.data?.message||n("verifyEmail.resendFailed"));else u.error(n("verifyEmail.resendFailed"))}finally{h.value=!1}};return O(()=>{E.value&&B()}),H(()=>{v&&clearInterval(v),y&&clearInterval(y)}),(e,o)=>{const b=Y;return i(),a("div",W,[r("div",X,[r("h1",z,s(e.$t("verifyEmail.title")),1),r("p",G,[t(m)?(i(),a("span",K,s(e.$t("verifyEmail.verifying")),1)):t(l)?(i(),a("span",Z,s(e.$t("verifyEmail.sentTo",{email:t(l)})),1)):(i(),a("span",ee,s(e.$t("verifyEmail.processing")),1))])]),t(_)?(i(),a("div",te,[f(s(t(_))+" ",1),r("p",se,s(e.$t("verifyEmail.autoRedirect",{seconds:t(g)})),1)])):k("",!0),t(x)?(i(),a("div",ae,s(t(x)),1)):k("",!0),t(m)?(i(),a("div",ie,[...o[2]||(o[2]=[r("div",{class:"border-primary h-6 w-6 animate-spin rounded-full border-b-2"},null,-1)])])):k("",!0),!t(E)&&!t(m)?(i(),a("div",ne,[r("div",oe,[r("p",re,s(e.$t("verifyEmail.resendPrompt")),1)]),t(l)?(i(),a("div",le,[$(b,{type:"button",class:"w-full",disabled:t(h)||t(d)>0,onClick:S},{default:C(()=>[t(d)>0?(i(),a(w,{key:0},[f(s(e.$t("verifyEmail.resendCountdown",{seconds:t(d)})),1)],64)):(i(),a(w,{key:1},[f(s(e.$t("verifyEmail.resendButton")),1)],64))]),_:1},8,["disabled"]),r("p",de,s(e.$t("verifyEmail.checkSpam")),1)])):(i(),a("div",ce,[r("div",ue,[j(r("input",{"onUpdate:modelValue":o[0]||(o[0]=p=>Q(l)?l.value=p:null),type:"email",placeholder:e.$t("verifyEmail.enterEmail"),class:"border-input bg-background focus-visible:ring-ring w-full rounded-md border px-3 py-2 text-sm shadow-sm outline-none focus-visible:ring-2 focus-visible:ring-offset-2"},null,8,fe),[[J,t(l)]]),$(b,{type:"button",class:"w-full",disabled:t(h)||t(d)>0,onClick:S},{default:C(()=>[t(d)>0?(i(),a(w,{key:0},[f(s(e.$t("verifyEmail.resendCountdown",{seconds:t(d)})),1)],64)):(i(),a(w,{key:1},[f(s(e.$t("verifyEmail.sendActivation")),1)],64))]),_:1},8,["disabled"])]),r("p",me,s(e.$t("verifyEmail.enterEmailPrompt")),1)])),$(b,{type:"button",variant:"outline",onClick:o[1]||(o[1]=p=>("navigateTo"in e?e.navigateTo:t(V))("/sign-up")),class:"w-full"},{default:C(()=>[f(s(e.$t("verifyEmail.backToSignUp")),1)]),_:1})])):k("",!0)])}}});export{Ee as default};
