import{h as R,e as B,u as D,B as I,D as V,E as l,W as O,c as i,o as u,a as s,I as b,t as r,g as a,d as g,b as y,$ as k,a0 as x,X as T,a6 as A,w as $,L,O as E,Q as n,P as K}from"./BzhixHsn.js";import{s as M}from"./D-0Ld2CH.js";const U={class:"flex flex-col gap-6"},W={class:"flex flex-col items-center gap-2 text-center"},H={class:"text-2xl font-bold"},q={class:"text-muted-foreground text-sm text-balance"},F={key:0,class:"rounded-md border border-green-200 bg-green-50 p-3 text-sm text-green-600"},Q={class:"mt-2 text-xs"},X={key:1,class:"rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-600"},j={key:2,class:"space-y-4"},z={class:"space-y-2"},G={for:"password",class:"text-sm font-medium"},J=["placeholder"],Y={class:"text-muted-foreground text-xs"},Z={class:"space-y-2"},ee={for:"confirmPassword",class:"text-sm font-medium"},se=["placeholder"],te={key:0,class:"flex items-center gap-2"},oe={key:1},re={class:"text-center"},le=R({__name:"reset-password",setup(ae){const{t}=B();D({title:t("pageTitle.resetPassword")});const S=I(),{$api:C}=V(),p=l(S.query.token||""),d=l(""),f=l(""),w=l(!1),m=l(!1),v=l(0);let c=null;const N=()=>{v.value=3,c=M(()=>{v.value--,v.value<=0&&(clearInterval(c),c=null,E("/sign-in"))},1e3)},h=async()=>{if(!p.value){n.error(t("resetPassword.invalidToken"));return}if(!d.value){n.error(t("resetPassword.enterPassword"));return}if(d.value.length<8){n.error(t("resetPassword.passwordTooShort"));return}if(d.value!==f.value){n.error(t("resetPassword.passwordMismatch"));return}w.value=!0;try{await C("/v1/auth/reset-password",{method:"POST",body:{token:p.value,password:d.value}}),m.value=!0,n.success(t("resetPassword.success")),N()}catch(e){if(e instanceof K)if(e.statusCode===400){const o=e.data?.detail;o==="RESET_PASSWORD_INVALID_TOKEN"?n.error(t("resetPassword.tokenExpired")):o==="RESET_PASSWORD_BAD_TOKEN"?n.error(t("resetPassword.invalidToken")):n.error(t("resetPassword.failed"))}else n.error(t("resetPassword.failed"));else n.error(t("resetPassword.failed"))}finally{w.value=!1}};return O(()=>{c&&clearInterval(c)}),(e,o)=>{const _=L;return u(),i("div",U,[s("div",W,[s("h1",H,r(e.$t("resetPassword.title")),1),s("p",q,r(e.$t("resetPassword.description")),1)]),a(m)?(u(),i("div",F,[g(r(e.$t("resetPassword.successMessage"))+" ",1),s("p",Q,r(e.$t("resetPassword.autoRedirect",{seconds:a(v)})),1)])):b("",!0),!a(m)&&!a(p)?(u(),i("div",X,r(e.$t("resetPassword.missingToken")),1)):b("",!0),!a(m)&&a(p)?(u(),i("div",j,[s("div",z,[s("label",G,r(e.$t("resetPassword.newPasswordLabel")),1),k(s("input",{id:"password","onUpdate:modelValue":o[0]||(o[0]=P=>T(d)?d.value=P:null),type:"password",placeholder:e.$t("resetPassword.passwordPlaceholder"),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,J),[[x,a(d)]]),s("p",Y,r(e.$t("resetPassword.passwordHint")),1)]),s("div",Z,[s("label",ee,r(e.$t("resetPassword.confirmPasswordLabel")),1),k(s("input",{id:"confirmPassword","onUpdate:modelValue":o[1]||(o[1]=P=>T(f)?f.value=P:null),type:"password",placeholder:e.$t("resetPassword.confirmPasswordPlaceholder"),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:A(h,["enter"])},null,40,se),[[x,a(f)]])]),y(_,{type:"button",class:"w-full",disabled:a(w),onClick:h},{default:$(()=>[a(w)?(u(),i("span",te,[o[3]||(o[3]=s("div",{class:"h-4 w-4 animate-spin rounded-full border-b-2 border-white"},null,-1)),g(" "+r(e.$t("resetPassword.resetting")),1)])):(u(),i("span",oe,r(e.$t("resetPassword.resetButton")),1))]),_:1},8,["disabled"]),s("div",re,[y(_,{type:"button",variant:"link",onClick:o[2]||(o[2]=P=>("navigateTo"in e?e.navigateTo:a(E))("/sign-in"))},{default:$(()=>[g(r(e.$t("resetPassword.backToLogin")),1)]),_:1})])])):b("",!0)])}}});export{le as default};
