import{r,j as e}from"./jsx-runtime-BMrMXMSG.js";import{u as _,F as T,a as j}from"./index-BvM5axzC.js";import{A as B,H as R}from"./Heading-XaJD9TaV.js";import{P as U}from"./PasswordCriteria-KH_F8Z_3.js";import{B as P}from"./button-B6K71EBC.js";import{u as q,D}from"./dialog-CvN3Q5Ey.js";import{u as H}from"./use-toast-8lerf42F.js";import{d as O,e as V}from"./index-XrU1i-Uc.js";import{k as Y}from"./components-Cr-DqYPJ.js";import{C as I,T as i}from"./triangle-alert-DbGJ6_AS.js";import"./utils-Br2EXFOw.js";import"./authSlice-wB7ecGB_.js";import"./index-CukTLwcq.js";import"./x-BXrg1M6t.js";const b=t=>({specialCharacter:/[#?!@$%^&*-]/.test(t),containsUppercase:/[A-Z]/.test(t),containsLowercase:/[a-z]/.test(t),containsNumber:/[0-9]/.test(t),eightCharacter:t.length>=8}),rs=()=>{const[t,N]=r.useState({specialCharacter:!1,containsUppercase:!1,containsLowercase:!1,containsNumber:!1,eightCharacter:!1}),[C,v]=r.useState(!1),y=O(),{toast:o}=H(),{uid:L,token:k}=V(),n=_(),{handleSubmit:S,watch:A}=n,c=A("new_password1"),[z,{isLoading:F}]=q();r.useEffect(()=>{N(b(c||""))},[c]);const l=a=>{const s=b(a);return s.eightCharacter?s.containsUppercase?s.containsLowercase?s.containsNumber?s.specialCharacter?!0:"Password must contain at least one special character.":"Password must contain at least one number.":"Password must contain at least one lowercase letter.":"Password must contain at least one uppercase letter.":"Password must be at least 8 characters long."},E=a=>{z({...a,uid:L,token:k}).unwrap().then(s=>{console.log(s),s!=null&&s.success&&v(!0)}).catch(s=>{var d,u,m,p,f,w,g,h,x;(u=(d=s==null?void 0:s.data)==null?void 0:d.data)!=null&&u.non_field_errors?o({title:"An error occurred",description:(p=(m=s==null?void 0:s.data)==null?void 0:m.data)==null?void 0:p.token[0],variant:"destructive",icon:e.jsx(i,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):(f=s==null?void 0:s.data)!=null&&f.data?o({title:"An error occurred",description:(g=(w=s==null?void 0:s.data)==null?void 0:w.data)!=null&&g.uid[0]?(x=(h=s==null?void 0:s.data)==null?void 0:h.data)==null?void 0:x.uid[0]:"Something went wrong, please try again",variant:"destructive",icon:e.jsx(i,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):o({title:"An error occurred",description:"Something went wrong, please try again",variant:"destructive",icon:e.jsx(i,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})})}),console.log(a)};return e.jsxs(B,{title:"",subtitle:"",children:[e.jsx(T,{...n,children:e.jsxs("form",{className:"flex flex-col gap-5 w-full",onSubmit:S(E),children:[e.jsx(R,{title:"Change Password",subtitle:"Enter new password and confirm password to reset your forgotten password"}),e.jsx(j,{validateFn:l,type:"password",fieldName:"new_password1",fieldLabel:"New Password",isValidated:!0,required:!0}),e.jsx(U,{criteria:t}),e.jsx(j,{validateFn:l,type:"password",fieldName:"new_password2",fieldLabel:"Confrim Password",isValidated:!0,required:!0}),e.jsx(P,{size:"lg",text:"Reset Password",isLoading:F}),e.jsx(Y,{to:"/user/login",className:"text-primary mx-auto",children:"Back To Login"})]})}),e.jsx(D,{isOpen:C,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(I,{color:"green",size:35,className:"bg-green-100 p-2 rounded-lg absolute top-6"}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold",children:"Password has successfully reset"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Your password has been successfully reset. You can now login with your new password."})]}),e.jsx("hr",{}),e.jsx(P,{variant:"default",className:"w-full",onClick:()=>{y("/user/login")},text:"Proceed to login"})]})})]})};export{rs as default};
