import{r as j,j as s}from"./jsx-runtime-BMrMXMSG.js";import{B as h}from"./button-B6K71EBC.js";import{A as P,H as R}from"./Heading-XaJD9TaV.js";import{u as C,F as E,a as H}from"./index-BvM5axzC.js";import{a as _,D as B}from"./dialog-CvN3Q5Ey.js";import{t as i}from"./use-toast-8lerf42F.js";import{d as D}from"./index-XrU1i-Uc.js";import{k as M}from"./components-Cr-DqYPJ.js";import{C as O,T as o}from"./triangle-alert-DbGJ6_AS.js";import"./utils-Br2EXFOw.js";import"./authSlice-wB7ecGB_.js";import"./index-CukTLwcq.js";import"./x-BXrg1M6t.js";const b={title:"",subtitle:""},N={title:"Reset Password",subtitle:"A reset link will be sent to your email"},$=()=>{const v=D(),[w,y]=j.useState(!1),[A,k]=j.useState(""),a=C(),{handleSubmit:S}=a,[z,{isLoading:F}]=_(),L=e=>{z(e).unwrap().then(t=>{t!=null&&t.success&&(k(e==null?void 0:e.email),y(!0))}).catch(t=>{var n,l,d,c,r,m,u,p,x,f,g;(l=(n=t==null?void 0:t.data)==null?void 0:n.data)!=null&&l.non_field_errors?i({title:"An error occurred",description:(c=(d=t==null?void 0:t.data)==null?void 0:d.data)==null?void 0:c.non_field_errors[0],variant:"destructive",icon:s.jsx(o,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):(r=t==null?void 0:t.data)!=null&&r.data?i({title:"An error occurred",description:(u=(m=t==null?void 0:t.data)==null?void 0:m.data)!=null&&u.username[0]?(x=(p=t==null?void 0:t.data)==null?void 0:p.data)==null?void 0:x.username[0]:(g=(f=t==null?void 0:t.data)==null?void 0:f.data)==null?void 0:g.email[0],variant:"destructive",icon:s.jsx(o,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):i({title:"An error occurred",description:"Something went wrong, please try again",variant:"destructive",icon:s.jsx(o,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})})})};return s.jsxs(P,{title:b.title,subtitle:b.subtitle,children:[s.jsxs(E,{...a,children:[s.jsxs("form",{className:"flex flex-col gap-5 w-full",onSubmit:S(L),children:[s.jsx(R,{title:N.title,subtitle:N.subtitle}),s.jsx(H,{type:"email",fieldName:"email",required:!0}),s.jsx(h,{size:"lg",text:"Send Reset Link",isLoading:F})]}),s.jsxs("p",{className:"flex gap-2 justify-center items-center font-semibold my-4",children:["Not you?",s.jsx(M,{to:"/user/login",className:"text-primary",children:"Log in"})]})]}),s.jsx(B,{isOpen:w,children:s.jsxs("div",{className:"space-y-4",children:[s.jsx(O,{color:"green",size:35,className:"bg-green-100 p-2 rounded-lg absolute top-6"}),s.jsxs("div",{children:[s.jsx("h2",{className:"text-2xl font-semibold",children:"Reset password link sent"}),s.jsxs("p",{className:"text-sm text-muted-foreground",children:["A reset passsword link has been sent to ",A]})]}),s.jsx("hr",{}),s.jsx(h,{variant:"default",className:"w-full",onClick:()=>{v("/user/login")},text:"Go to login"})]})})]})};export{$ as default};
