import{r as d,j as s,B as P,q as F,t as v}from"./index-Cc987VYg.js";import{u as S,F as E,a as l,b as c,c as i,d as m,e as w}from"./form-CirgXhnc.js";import{a as _}from"./zod-BQ5psN1t.js";import{I as u}from"./input-DPNG9e3H.js";import{u as q,c as k}from"./reset-password.schema-CpuO5jb1.js";import{E as h}from"./eye-off-DI70rQvm.js";import{E as x}from"./eye-CXkzLhIn.js";import{L as I}from"./label-npsA0UlW.js";function z({onSuccess:p}){const[a,j]=d.useState(!1),[t,f]=d.useState(!1),[n,b]=d.useState(!1),{changePassword:g,isChangingPassword:o}=q(),r=S({resolver:_(k),defaultValues:{old_password:"",new_password:"",new_password_confirm:""}}),N=async e=>{try{await g(e),r.reset(),p?.(),setTimeout(()=>{window.location.href="/login"},2e3)}catch(y){const C=F(y)||"Failed to change password";v.error(C)}};return s.jsx(E,{...r,children:s.jsxs("form",{onSubmit:r.handleSubmit(N),className:"space-y-6",children:[s.jsx(l,{control:r.control,name:"old_password",render:({field:e})=>s.jsxs(c,{children:[s.jsx(i,{required:!0,children:"Current Password"}),s.jsx(m,{children:s.jsxs("div",{className:"relative",children:[s.jsx(u,{type:a?"text":"password",placeholder:"Enter your current password",...e,disabled:o,autoComplete:"current-password"}),s.jsx("button",{type:"button",onClick:()=>j(!a),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:a?s.jsx(h,{className:"h-4 w-4"}):s.jsx(x,{className:"h-4 w-4"})})]})}),s.jsx(w,{})]})}),s.jsx(l,{control:r.control,name:"new_password",render:({field:e})=>s.jsxs(c,{children:[s.jsx(i,{required:!0,children:"New Password"}),s.jsx(m,{children:s.jsxs("div",{className:"relative",children:[s.jsx(u,{type:t?"text":"password",placeholder:"Enter your new password",...e,disabled:o,autoComplete:"new-password"}),s.jsx("button",{type:"button",onClick:()=>f(!t),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:t?s.jsx(h,{className:"h-4 w-4"}):s.jsx(x,{className:"h-4 w-4"})})]})}),s.jsx(w,{}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Password must be at least 8 characters with uppercase, lowercase, number, and special character"})]})}),s.jsx(l,{control:r.control,name:"new_password_confirm",render:({field:e})=>s.jsxs(c,{children:[s.jsx(i,{required:!0,children:"Confirm New Password"}),s.jsx(m,{children:s.jsxs("div",{className:"relative",children:[s.jsx(u,{type:n?"text":"password",placeholder:"Confirm your new password",...e,disabled:o,autoComplete:"new-password"}),s.jsx("button",{type:"button",onClick:()=>b(!n),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:n?s.jsx(h,{className:"h-4 w-4"}):s.jsx(x,{className:"h-4 w-4"})})]})}),s.jsx(w,{})]})}),s.jsxs(P,{type:"submit",className:"w-full",disabled:o,children:[o&&s.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}),"Change Password"]})]})})}export{z as C};
