1import{r as o,j as e}from"./react-vendor-DDlTsOEd.js";import{c as O,d as x,S as q,a1 as y,a8 as Y,N as Z,O as F}from"./index-BBAL-XO_.js";import{E as L}from"./eye-off-DUeHB1ln.js";import{E as R}from"./eye-CPa9T2gm.js";function K(){const{toast:l}=O(),[j,i]=o.useState(null),[c,g]=o.useState(""),[t,h]=o.useState(""),[n,m]=o.useState(""),[v,N]=o.useState(!1),[P,S]=o.useState(!1),[p,b]=o.useState(!1);o.useEffect(()=>{x.get("/auth/me").then(s=>i(s.data?.hasPassword!==!1)).catch(()=>i(!0))},[]);const a=j===!1,u=(()=>{if(!t)return 0;let s=0;return t.length>=8&&s++,/[A-Z]/.test(t)&&s++,/[0-9]/.test(t)&&s++,/[^A-Za-z0-9]/.test(t)&&s++,s})(),C=["","Weak","Fair","Good","Strong"][u]??"",w=["","bg-red-400","bg-amber-400","bg-blue-400","bg-green-400"][u]??"bg-gray-200";async function k(s){if(s.preventDefault(),t!==n){l({title:"Passwords don't match",variant:"destructive"});return}if(t.length<8){l({title:"Password must be at least 8 characters",variant:"destructive"});return}b(!0);try{const r=a?await x.post("/auth/set-password",{newPassword:t}):await x.put("/auth/change-password",{currentPassword:c,newPassword:t}),d=Z();r.data?.token&&d&&F(r.data.token,d),l({title:a?"Password set!":"Password changed!",description:a?"You can now sign in with your email and this password.":"Your password has been updated successfully."}),a&&i(!0),g(""),h(""),m("")}catch(r){l({title:"Failed to change password",description:r.message,variant:"destructive"})}finally{b(!1)}}function f({value:s,onChange:r,show:d,onToggle:E,placeholder:z}){return e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:d?"text":"password",value:s,onChange:A=>r(A.target.value),placeholder:z,required:!0,className:"w-full px-4 py-2.5 pr-11 bg-gray-50 border border-gray-200 rounded-xl text-sm text-gray-900 placeholder:text-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-400 transition-colors"}),e.jsx("button",{type:"button",onClick:E,className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-900 hover:text-gray-600",children:d?e.jsx(L,{size:16}):e.jsx(R,{size:16})})]})}return e.jsx(q,{title:a?"Set Password":"Change Password",subtitle:a?"Add a password so you can sign in without a link":"Keep your account secure",backHref:"/dashboard",backLabel:"Dashboard",children:e.jsx("div",{className:"max-w-lg",children:e.jsxs("div",{className:"bg-white rounded-2xl border border-gray-100 shadow-sm p-6",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6 pb-5 border-b border-gray-100",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-red-50 flex items-center justify-center",children:e.jsx(y,{size:18,className:"text-red-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-bold text-gray-900",children:a?"Set Your Password":"Update Password"}),e.jsx("p",{className:"text-xs text-gray-900",children:a?"You signed in with a link, so there is no current password to enter":"Choose a strong, unique password"})]})]}),e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[!a&&e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-gray-900 mb-1.5 block",children:"Current Password"}),e.jsx(f,{value:c,onChange:g,show:v,onToggle:()=>N(s=>!s),placeholder:"Enter current password"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-gray-900 mb-1.5 block",children:a?"Password":"New Password"}),e.jsx(f,{value:t,onChange:h,show:P,onToggle:()=>S(s=>!s),placeholder:"Enter new password"}),t&&e.jsxs("div",{className:"mt-2",children:[e.jsx("div",{className:"flex gap-1 h-1",children:[1,2,3,4].map(s=>e.jsx("div",{className:`flex-1 rounded-full transition-colors ${s<=u?w:"bg-gray-200"}`},s))}),e.jsx("p",{className:`text-xs mt-1 font-medium ${w.replace("bg-","text-")}`,children:C})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-semibold text-gray-900 mb-1.5 block",children:a?"Confirm Password":"Confirm New Password"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:"password",value:n,onChange:s=>m(s.target.value),placeholder:"Re-enter new password",required:!0,className:"w-full px-4 py-2.5 bg-gray-50 border border-gray-200 rounded-xl text-sm text-gray-900 placeholder:text-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500/30 focus:border-blue-400 transition-colors"}),n&&t===n&&e.jsx(Y,{size:16,className:"absolute right-3 top-1/2 -translate-y-1/2 text-green-500"})]})]}),e.jsxs("div",{className:"bg-gray-50 border border-gray-100 rounded-xl p-3 text-xs text-gray-900 space-y-1",children:[e.jsx("p",{className:"font-semibold text-gray-900 mb-1",children:"Password requirements:"}),[["At least 8 characters",t.length>=8],["One uppercase letter",/[A-Z]/.test(t)],["One number",/[0-9]/.test(t)],["One special character",/[^A-Za-z0-9]/.test(t)]].map(([s,r])=>e.jsxs("p",{className:r?"text-green-600":"",children:[r?"â":"â"," ",s]},s))]}),e.jsxs("button",{type:"submit",disabled:p||!a&&!c||!t||!n,className:"w-full flex items-center justify-center gap-2 bg-red-600 hover:bg-red-700 disabled:opacity-50 text-white font-medium text-sm px-5 py-2.5 rounded-xl transition-colors",children:[e.jsx(y,{size:16}),p?"Savingâ¦":a?"Set Password":"Update Password"]})]})]})})})}export{K as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.