import{h as x,e as k,u as C,D as T,E as g,W as I,c as u,o as f,a as t,I as E,t as r,g as o,b as _,$ as N,a0 as L,a6 as S,X as V,w as h,d as b,L as B,O as D,Q as l,P as F}from"./BzhixHsn.js";import{s as O}from"./D-0Ld2CH.js";const R={class:"flex flex-col gap-6"},A={class:"flex flex-col items-center gap-2 text-center"},M={class:"text-2xl font-bold"},K={class:"text-muted-foreground text-sm text-balance"},U={key:0,class:"rounded-md border border-green-200 bg-green-50 p-3 text-sm text-green-600"},W={class:"space-y-4"},q={class:"space-y-2"},G={for:"email",class:"text-sm font-medium"},H=["placeholder"],Q={key:0,class:"flex items-center gap-2"},X={key:1},j={key:2},z={class:"text-center"},ee=x({__name:"forgot-password",setup(J){const{t:a}=k();C({title:a("pageTitle.forgotPassword")});const{$api:P}=T(),n=g(""),m=g(!1),w=g(!1),d=g(0);let i=null;const y=()=>{d.value=60,i=O(()=>{d.value--,d.value<=0&&(clearInterval(i),i=null)},1e3)},v=async()=>{if(!n.value){l.error(a("forgotPassword.enterEmail"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(n.value)){l.error(a("forgotPassword.invalidEmail"));return}m.value=!0;try{await P("/v1/auth/forgot-password",{method:"POST",body:{email:n.value}}),w.value=!0,l.success(a("forgotPassword.emailSent")),y()}catch(s){if(s instanceof F)if(s.statusCode===429){const c=(s.data?.detail||"").match(/(\d+)\s*seconds?/),$=c?c[1]:"60";l.error(a("forgotPassword.rateLimitError",{seconds:$}))}else s.statusCode===400&&s.data?.detail==="FORGOT_PASSWORD_INVALID_EMAIL"?l.error(a("forgotPassword.emailNotFound")):l.error(a("forgotPassword.sendFailed"));else l.error(a("forgotPassword.sendFailed"))}finally{m.value=!1}};return I(()=>{i&&clearInterval(i)}),(e,s)=>{const p=B;return f(),u("div",R,[t("div",A,[t("h1",M,r(e.$t("forgotPassword.title")),1),t("p",K,r(e.$t("forgotPassword.description")),1)]),o(w)?(f(),u("div",U,r(e.$t("forgotPassword.successMessage",{email:o(n)})),1)):E("",!0),t("div",W,[t("div",q,[t("label",G,r(e.$t("forgotPassword.emailLabel")),1),N(t("input",{id:"email","onUpdate:modelValue":s[0]||(s[0]=c=>V(n)?n.value=c:null),type:"email",placeholder:e.$t("forgotPassword.emailPlaceholder"),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",onKeyup:S(v,["enter"])},null,40,H),[[L,o(n)]])]),_(p,{type:"button",class:"w-full",disabled:o(m)||o(d)>0,onClick:v},{default:h(()=>[o(m)?(f(),u("span",Q,[s[2]||(s[2]=t("div",{class:"h-4 w-4 animate-spin rounded-full border-b-2 border-white"},null,-1)),b(" "+r(e.$t("forgotPassword.sending")),1)])):o(d)>0?(f(),u("span",X,r(e.$t("forgotPassword.resendCountdown",{seconds:o(d)})),1)):(f(),u("span",j,r(e.$t("forgotPassword.sendButton")),1))]),_:1},8,["disabled"]),t("div",z,[_(p,{type:"button",variant:"link",onClick:s[1]||(s[1]=c=>("navigateTo"in e?e.navigateTo:o(D))("/sign-in"))},{default:h(()=>[b(r(e.$t("forgotPassword.backToLogin")),1)]),_:1})])])])}}});export{ee as default};
