import{r as n,j as t}from"./jsx-runtime-BMrMXMSG.js";import{u as B,F as V,a as o}from"./index-BvM5axzC.js";import{b as G,c as Z,D as J}from"./dialog-CvN3Q5Ey.js";import{A as K,H as Q}from"./Heading-XaJD9TaV.js";import{S as W}from"./SocialAuth-khL-ycbD.js";import{P as X}from"./PasswordCriteria-KH_F8Z_3.js";import{B as c}from"./button-B6K71EBC.js";import{u as Y}from"./use-toast-8lerf42F.js";import{d as ee}from"./index-XrU1i-Uc.js";import{k as te}from"./components-Cr-DqYPJ.js";import{C as P,T as l}from"./triangle-alert-DbGJ6_AS.js";import"./utils-Br2EXFOw.js";import"./index-CukTLwcq.js";import"./x-BXrg1M6t.js";import"./authSlice-wB7ecGB_.js";const k=a=>({specialCharacter:/[#?!@$%^&*-]/.test(a),containsUppercase:/[A-Z]/.test(a),containsLowercase:/[a-z]/.test(a),containsNumber:/[0-9]/.test(a),eightCharacter:a.length>=8}),he=()=>{const{toast:a}=Y(),z=ee(),[d,A]=n.useState(""),[_,q]=n.useState(!1),[r,u]=n.useState(900),[m,p]=n.useState(!0),[E,O]=n.useState({specialCharacter:!1,containsUppercase:!1,containsLowercase:!1,containsNumber:!1,eightCharacter:!1}),f=B(),{handleSubmit:T,watch:U}=f,x=U("password");n.useEffect(()=>{if(r>0){const s=setInterval(()=>{u(e=>e-1)},1e3);return()=>clearInterval(s)}else p(!1)},[r]);const[D,{isLoading:F}]=G(),[I,{isLoading:g}]=Z();n.useEffect(()=>{O(k(x||""))},[x]);const $=s=>{const e=k(s);return e.eightCharacter?e.containsUppercase?e.containsLowercase?e.containsNumber?e.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."},R=s=>{const e=Math.floor(s/60),i=s%60;return`${e}:${i<10?`0${i}`:i}`},H=()=>{D({email:d}),u(900),p(!0)},M=s=>{I(s).unwrap().then(e=>{var i;e!=null&&e.success&&(A(s==null?void 0:s.email),q(!0),a({title:"Account created successfully",description:(i=e==null?void 0:e.data)==null?void 0:i.detail,variant:"success",icon:t.jsx(P,{color:"green",size:35,className:"bg-green-100 p-1 rounded"})}))}).catch(e=>{var i,h,j,N,b,w,v,S,y,C,L;(h=(i=e==null?void 0:e.data)==null?void 0:i.data)!=null&&h.non_field_errors?a({title:"An error occurred",description:(N=(j=e==null?void 0:e.data)==null?void 0:j.data)==null?void 0:N.non_field_errors[0],variant:"destructive",icon:t.jsx(l,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):(b=e==null?void 0:e.data)!=null&&b.data?a({title:"An error occurred",description:(v=(w=e==null?void 0:e.data)==null?void 0:w.data)!=null&&v.username[0]?(y=(S=e==null?void 0:e.data)==null?void 0:S.data)==null?void 0:y.username[0]:(L=(C=e==null?void 0:e.data)==null?void 0:C.data)==null?void 0:L.email[0],variant:"destructive",icon:t.jsx(l,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):a({title:"An error occurred",description:"Something went wrong, please try again",variant:"destructive",icon:t.jsx(l,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})})})};return t.jsxs(K,{title:"Let's make something awesome together",subtitle:"Sign up to start creating, customizing, and shopping for personalized products. It's super easy!",children:[t.jsx(V,{...f,children:t.jsxs("form",{className:"flex flex-col gap-5 w-full",onSubmit:T(M),children:[t.jsx(Q,{title:"Sign Up",subtitle:"Let's go! Create an account ✨"}),t.jsxs("div",{className:"flex gap-5",children:[t.jsx(o,{type:"text",fieldName:"first_name",required:!0}),t.jsx(o,{type:"text",fieldName:"last_name",required:!0})]}),t.jsxs("div",{className:"flex gap-5",children:[t.jsx(o,{type:"text",fieldName:"username",required:!0}),t.jsx(o,{type:"phone",fieldName:"phone_number",required:!0})]}),t.jsx(o,{type:"email",fieldName:"email",required:!0}),t.jsx(o,{validateFn:$,type:"password",fieldName:"password",isValidated:!0,required:!0}),t.jsx(X,{criteria:E}),t.jsx(c,{size:"lg",text:"Sign Up",isLoading:g}),t.jsx(W,{displayText:"or sign up with"}),t.jsxs("p",{className:"flex gap-2 justify-center mb-10 font-semibold",children:["Have an account already?"," ",t.jsx(te,{to:"/user/login",className:"text-primary",children:"Log in"})]})]})}),t.jsx(J,{isOpen:_,children:t.jsxs("div",{className:"space-y-4",children:[t.jsx(P,{color:"green",size:35,className:"bg-green-100 p-2 rounded-lg absolute top-6"}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-2xl font-semibold",children:"Verification email sent"}),t.jsxs("p",{className:"text-sm text-muted-foreground",children:["A verification email has been sent to ",d]}),t.jsxs("p",{className:"flex gap-2 text-sm text-muted-foreground my-4",children:["Didn't the link?",t.jsx(c,{onClick:H,variant:"link",size:"link",className:"text-sm",text:F?"Sending, please wait...":m?`Resend in ${R(r)}`:"Send a new code",disabled:m||g})]})]}),t.jsx("hr",{}),t.jsx(c,{variant:"default",className:"w-full",onClick:()=>{z("/user/login")},text:"Go to login"})]})})]})};export{he as default};
