import{i as $,n as ss,r as a,j as e,G as u,t as o,o as es,T as m,B as ts,p as as,q as N,A as U}from"./vendor-BuNhBR-q.js";import{P as os,i as rs,l as ns,e as is,j as ls,k as cs}from"./index-DzxWaMzc.js";const ms=()=>{const x=$(),q=ss(),[h,B]=a.useState(""),[p,D]=a.useState(""),[r,L]=a.useState(""),[n,G]=a.useState(""),[F,V]=a.useState(""),[X,Y]=a.useState(""),[J,i]=a.useState(!1),[K,l]=a.useState(!1),[g,f]=a.useState(!1),c=t=>{V(t),i(!0)},M=t=>{Y(t),l(!0)};a.useEffect(()=>{const t=new URLSearchParams(x.search);B(t.get("email")||""),D(t.get("token")||"")},[x.search]);const Q=async t=>{var w,S,j,y,v,E,P,b,C,k,R,A,T,W,O,I,_,z,H;if(t.preventDefault(),r!==n){c("Passwords do not match");return}f(!0);const Z={email:h,reset_token:p,password:r,password_confirmation:n};try{const s=await is.post(ls(cs.resetPassword),Z);if(console.log("API RESPONSE:",s.data),((w=s==null?void 0:s.data)==null?void 0:w.success)===!0)M("Password set successfully!"),setTimeout(()=>q("/auth/login"),1200);else{const d=((S=s==null?void 0:s.data)==null?void 0:S.message)||((v=(y=(j=s==null?void 0:s.data)==null?void 0:j.errors)==null?void 0:y.password)==null?void 0:v[0])||((b=(P=(E=s==null?void 0:s.data)==null?void 0:E.errors)==null?void 0:P.password_confirmation)==null?void 0:b[0])||"Unable to reset password";c(d)}}catch(s){console.log("RESET ERR RESPONSE:",(C=s==null?void 0:s.response)==null?void 0:C.data);const d=((R=(k=s==null?void 0:s.response)==null?void 0:k.data)==null?void 0:R.message)||((O=(W=(T=(A=s==null?void 0:s.response)==null?void 0:A.data)==null?void 0:T.errors)==null?void 0:W.password)==null?void 0:O[0])||((H=(z=(_=(I=s==null?void 0:s.response)==null?void 0:I.data)==null?void 0:_.errors)==null?void 0:z.reset_token)==null?void 0:H[0])||(s==null?void 0:s.message);c(d||"Server error. Try again.")}finally{f(!1)}};return e.jsxs(os,{title:"Reset Password",description:"Create your account password",children:[e.jsxs(u,{container:!0,spacing:0,sx:{minHeight:"100vh",overflowX:"hidden",backgroundColor:"#ffffff"},children:[e.jsx(u,{item:!0,xs:12,md:6,sx:{backgroundColor:"#00265C",display:{xs:"none",md:"flex"},justifyContent:"center",alignItems:"center",p:4},children:e.jsx(o,{component:"img",src:rs,alt:"Illustration",sx:{width:"100%",maxWidth:380}})}),e.jsx(u,{item:!0,xs:12,md:6,display:"flex",justifyContent:"center",alignItems:"center",children:e.jsxs(o,{sx:{width:"100%",maxWidth:500,px:{xs:3,sm:4,md:6},py:{xs:6,md:0},animation:"fadeInUp 0.6s ease-out"},children:[e.jsx(o,{sx:{mb:4,textAlign:"center"},children:e.jsx(o,{component:"img",src:ns,alt:"Veerayee HR",sx:{width:"100%",maxWidth:200,mx:"auto"}})}),e.jsx(es,{variant:"h6",sx:{mb:3,fontWeight:500,textAlign:"center",color:"#000"},children:"Set Your Account Password"}),e.jsxs("form",{onSubmit:Q,children:[e.jsx(m,{label:"Email",value:h,fullWidth:!0,margin:"normal",InputProps:{readOnly:!0}}),e.jsx("input",{type:"hidden",value:p,name:"token"}),e.jsx(m,{type:"password",label:"New Password",value:r,onChange:t=>L(t.target.value),fullWidth:!0,margin:"normal",required:!0}),e.jsx(m,{type:"password",label:"Re-enter Password",value:n,onChange:t=>G(t.target.value),fullWidth:!0,margin:"normal",required:!0}),e.jsx(ts,{type:"submit",variant:"contained",fullWidth:!0,disabled:g,sx:{mt:3,py:1.5,fontSize:"16px",textTransform:"none"},children:g?e.jsx(as,{size:24,color:"inherit"}):"Reset Password"})]})]})})]}),e.jsx(N,{open:J,autoHideDuration:4e3,onClose:()=>i(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(U,{severity:"error",onClose:()=>i(!1),sx:{width:"100%"},children:F})}),e.jsx(N,{open:K,autoHideDuration:3e3,onClose:()=>l(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:e.jsx(U,{severity:"success",onClose:()=>l(!1),sx:{width:"100%"},children:X})})]})};export{ms as default};
