import{j as e}from"./query-PJ0ZdjbV.js";import{u as y,a}from"./vendor-CWhr2lg4.js";import{n as w,a3 as E,d as I,e as O,f as T,g as k,h as A,I as i,i as q,B,R as u,l as D,a4 as R}from"./index-BSPIaiZU.js";import{S as M}from"./shield-alert-1Mds4K4N.js";import{E as x}from"./eye-off-D-jqPqD8.js";import{E as g}from"./eye-DlIcvqP-.js";import"./ui-aO-W1bxx.js";function z(){const o=y(),n=w(s=>s.mustChangePassword),f=w(s=>s.setMustChangePassword),d=E(),[l,j]=a.useState(""),[t,C]=a.useState(""),[m,N]=a.useState(""),[h,b]=a.useState(!1),[c,S]=a.useState(!1),[p,r]=a.useState(""),v=s=>{if(s.preventDefault(),r(""),t!==m){r("New passwords do not match.");return}if(t===l){r("New password must be different from your current password.");return}d.mutate({old_password:l,new_password:t},{onSuccess:()=>{R.success("Password changed successfully."),n?(f(!1),o(u.DASHBOARD,{replace:!0})):o(u.SETTINGS,{replace:!0})},onError:P=>{r(D(P,"Could not change password. Please try again."))}})};return e.jsxs("div",{className:"mx-auto max-w-md space-y-6",children:[n&&e.jsxs("div",{className:"flex items-start gap-3 rounded-md border border-amber-200 bg-amber-50 px-4 py-3",children:[e.jsx(M,{className:"mt-0.5 h-5 w-5 shrink-0 text-amber-600"}),e.jsxs("div",{className:"text-[13px] text-amber-800",children:[e.jsx("p",{className:"font-medium",children:"Password change required"}),e.jsx("p",{className:"mt-0.5 text-amber-700",children:"Your password has expired or was reset by an administrator. Set a new password to continue."})]})]}),e.jsxs(I,{children:[e.jsxs(O,{children:[e.jsx(T,{children:"Change Password"}),e.jsx(k,{children:"Enter your current password, then choose a new one."})]}),e.jsxs("form",{onSubmit:v,children:[e.jsxs(A,{className:"space-y-4",children:[p&&e.jsx("p",{className:"text-sm text-destructive",children:p}),e.jsxs("div",{className:"relative",children:[e.jsx(i,{type:h?"text":"password",placeholder:"Current password",value:l,onChange:s=>j(s.target.value),autoComplete:"current-password",required:!0}),e.jsx("button",{type:"button",onClick:()=>b(s=>!s),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",tabIndex:-1,children:h?e.jsx(x,{className:"h-4 w-4"}):e.jsx(g,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(i,{type:c?"text":"password",placeholder:"New password",value:t,onChange:s=>C(s.target.value),autoComplete:"new-password",required:!0,minLength:8}),e.jsx("button",{type:"button",onClick:()=>S(s=>!s),className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",tabIndex:-1,children:c?e.jsx(x,{className:"h-4 w-4"}):e.jsx(g,{className:"h-4 w-4"})})]}),e.jsx(i,{type:c?"text":"password",placeholder:"Confirm new password",value:m,onChange:s=>N(s.target.value),autoComplete:"new-password",required:!0,minLength:8})]}),e.jsxs(q,{className:"flex flex-col gap-3",children:[e.jsx(B,{type:"submit",className:"w-full",disabled:d.isPending,children:d.isPending?"Saving...":"Change Password"}),!n&&e.jsx("button",{type:"button",onClick:()=>o(u.SETTINGS),className:"text-sm text-primary hover:underline",children:"Back to settings"})]})]})]})]})}export{z as ChangePasswordPage};
