import{N as X,x as $,n as J,w as K,f0 as U,r,aD as z,e,M as H,S as x,T as a,eX as Q,B as l,d1 as u,O as Y,k as Z,ad as _,f4 as ee,eV as se,A as T,G as I,J as ae,K as te}from"./index-_6SmYgWK.js";import{A as R,I as V}from"./IconExclamationCircle-kP-S1YaN.js";const oe=()=>{const m=X();$();const A=J(),j=K(),w=(...s)=>j(ae(...s)),f=(...s)=>j(te(...s)),L={label:"Email",name:"email",type:"email",placeholder:"user@company.com"},B={label:"Password",name:"password",type:"password",placeholder:"********"},N={label:"Confirm Password",name:"confirmPassword",type:"password",placeholder:"********"},G={label:"Reset Token",name:"resetToken",type:"text"},[M]=U(),q=M.get("token"),[y,g]=r.useState(""),[o,v]=r.useState(""),[P,k]=r.useState(""),[c,b]=r.useState(q??""),[S,d]=r.useState(!1),[h,i]=r.useState([]),{authRateLimitError:C,setAuthRateLimitError:D}=z(),F=()=>{A("/signin",{replace:!0})},O=async s=>{s.preventDefault();const t=[];i([]),D(null),c||t.push("Token cannot be left blank!"),o!==P&&t.push("New Password and Confirm Password do not match.");const E=ee(o);if(E.length>0&&t.push(...E),t.length>0){i(t);return}const W={user:{email:y,tempToken:c,password:o}};d(!0);try{const n=await se.resetPassword(W);i([]),d(!1),n.data&&(w({message:"Password reset successful",options:{key:new Date().getTime()+Math.random(),variant:"success",action:p=>e.jsx(T,{style:{color:"white"},onClick:()=>f(p),children:e.jsx(I,{})})}}),g(""),b(""),v(""),k(""),F())}catch(n){d(!1),i([typeof n.response.data=="object"?n.response.data.message:n.response.data]),w({message:"Failed to reset password!",options:{key:new Date().getTime()+Math.random(),variant:"error",persist:!0,action:p=>e.jsx(T,{style:{color:"white"},onClick:()=>f(p),children:e.jsx(I,{})})}})}};return r.useEffect(()=>{D(null)},[]),e.jsxs(e.Fragment,{children:[e.jsx(H,{children:e.jsxs(x,{flexDirection:"column",sx:{maxWidth:"480px",gap:3},children:[h&&h.length>0&&e.jsx(R,{icon:e.jsx(V,{}),variant:"filled",severity:"error",children:e.jsx("ul",{style:{margin:0},children:h.map((s,t)=>e.jsx("li",{children:s},t))})}),C&&e.jsx(R,{icon:e.jsx(V,{}),variant:"filled",severity:"error",children:C}),e.jsxs(x,{sx:{gap:1},children:[e.jsx(a,{variant:"h1",children:"Reset Password"}),e.jsxs(a,{variant:"body2",sx:{color:m.palette.grey[600]},children:[e.jsx(Q,{style:{color:m.palette.primary.main},to:"/signin",children:"Back to Login"}),"."]})]}),e.jsx("form",{onSubmit:O,children:e.jsxs(x,{sx:{width:"100%",flexDirection:"column",alignItems:"left",justifyContent:"center",gap:2},children:[e.jsxs(l,{children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(a,{children:["Email",e.jsx("span",{style:{color:"red"},children:" *"})]}),e.jsx(a,{align:"left"}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(u,{inputParam:L,onChange:s=>g(s),value:y,showDialog:!1})]}),e.jsxs(l,{children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(a,{children:["Reset Token",e.jsx("span",{style:{color:"red"},children:" *"})]}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(Y,{fullWidth:!0,type:"string",placeholder:"Paste in the reset token.",multiline:!0,rows:3,inputParam:G,onChange:s=>b(s.target.value),value:c,sx:{mt:"8px"}}),e.jsx(a,{variant:"caption",children:e.jsx("i",{children:"Please copy the token you received in your email."})})]}),e.jsxs(l,{children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(a,{children:["New Password",e.jsx("span",{style:{color:"red"},children:" *"})]}),e.jsx(a,{align:"left"}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(u,{inputParam:B,onChange:s=>v(s),value:o,showDialog:!1}),e.jsx(a,{variant:"caption",children:e.jsx("i",{children:"Password must be at least 8 characters long and contain at least one lowercase letter, one uppercase letter, one digit, and one special character."})})]}),e.jsxs(l,{children:[e.jsxs("div",{style:{display:"flex",flexDirection:"row"},children:[e.jsxs(a,{children:["Confirm Password",e.jsx("span",{style:{color:"red"},children:" *"})]}),e.jsx("div",{style:{flexGrow:1}})]}),e.jsx(u,{inputParam:N,onChange:s=>k(s),value:P,showDialog:!1}),e.jsx(a,{variant:"caption",children:e.jsx("i",{children:"Confirm your new password. Must match the password typed above."})})]}),e.jsx(Z,{variant:"contained",style:{borderRadius:12,height:40,marginRight:5},type:"submit",children:"Update Password"})]})})]})}),S&&e.jsx(_,{open:S})]})};export{oe as default};
