import{o as j,s as A,e as I,d as S,f as _,h as w,u as O,r as u,j as e,i as R,T as i,L as f,B as d,F as M,k as N,H as b,l as v,I as F,m as L,A as D,n,p as C,q as K,N as k,t as Y}from"./index-C7k9Fo_-.js";const g=j({email:A().trim().min(1,"fields.email.required").max(255).refine(s=>s===""||I().safeParse(s).success,{message:"fields.email.invalid"})});function V(){const s=S({resolver:_(g),defaultValues:{email:""}}),r={email:w(g,"email")};return{form:s,constraints:r}}const B=400,H={EMAIL_NOT_EXISTS:"VALIDATION",TOO_MANY_ATTEMPTS:"VALIDATION",EMAIL_RECOVERY_FAILED:"SERVER"},W={EMAIL_NOT_EXISTS:"forgotPassword.emailNotExists",TOO_MANY_ATTEMPTS:"forgotPassword.tooManyAttempts",EMAIL_RECOVERY_FAILED:"forgotPassword.emailRecoveryFailed"};function U(s){if(!s||typeof s!="object")return null;const r=s.error;return r==="EMAIL_NOT_EXISTS"||r==="TOO_MANY_ATTEMPTS"||r==="EMAIL_RECOVERY_FAILED"?r:null}function X(){const{form:s,constraints:r}=V(),{t}=O("auth"),[p,m]=u.useState(!1),[x,y]=u.useState(!1),h=async({email:o})=>{m(!0);try{await L("/auth/forgot-password",{method:"POST",body:{email:o},timeoutMs:15e3}),y(!0)}catch(a){if(a instanceof D){const c=U(a.body);c?n.emit({type:H[c],messageKey:W[c]}):n.emit({type:"UNKNOWN",messageKey:"forgotPassword.failed"})}else a instanceof Error&&a.name===C?n.emit({type:"NETWORK",messageKey:"forgotPassword.network"}):a instanceof TypeError?n.emit({type:"NETWORK",messageKey:"forgotPassword.network"}):n.emit({type:"UNKNOWN",messageKey:"forgotPassword.failed"})}finally{m(!1)}},{control:E,handleSubmit:T,formState:{errors:P}}=s,l=P.email?.message;return e.jsx(R,{style:{width:B},children:x?e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16,alignItems:"center"},children:[e.jsx(i,{variant:"body",children:t("forgotPassword.success")}),e.jsx(f,{to:"/login",children:e.jsx(d,{type:"link",children:t("forgotPassword.backToLogin")})})]}):e.jsx(M,{...s,children:e.jsx(N,{constraints:r,children:e.jsxs("form",{onSubmit:T(h),style:{display:"flex",flexDirection:"column",gap:16},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsx(i,{variant:"title",as:"h2",children:t("forgotPassword.title")}),e.jsx(i,{variant:"body",isSubtle:!0,children:t("forgotPassword.description")}),e.jsx(b,{noPrefix:!0,children:t("forgotPassword.noEmailHint")})]}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[e.jsx(i,{variant:"label",isBold:!0,children:t("fields.email.label")}),e.jsx(v,{name:"email",control:E,render:({field:o})=>e.jsx(F,{type:"text",value:o.value??"",onChange:o.onChange,onBlur:o.onBlur,name:o.name,placeholder:t("fields.email.placeholder"),error:!!l,autoFocus:!0,testId:"forgot-password-email"})}),l&&e.jsx(i,{variant:"caption",isDanger:!0,children:t(l)})]}),e.jsx(d,{htmlType:"submit",type:"primary",loading:p,style:{width:"100%"},testId:"forgot-password-submit",children:t("forgotPassword.submit")}),e.jsx(f,{to:"/login",style:{alignSelf:"center"},children:e.jsx(d,{type:"link",children:t("forgotPassword.backToLogin")})})]})})})})}function G(){const{isAuthenticated:s}=K();return s?e.jsx(k,{to:"/",replace:!0}):e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"100vh",padding:16,background:"var(--color-background-app)"},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:24},children:[e.jsx(Y,{}),e.jsx(X,{})]})})}export{G as default};
