import{j as e}from"./jsx-runtime.D_zvdyIk.js";import{r as i}from"./index.2yJIXLcc.js";import{B as g}from"./index.D9qG4eP_.js";import"./iconBase.Blz05Vck.js";const y=()=>{const[s,p]=i.useState({firstName:"",email:"",password:""}),[x,m]=i.useState(!1),[o,r]=i.useState([]),n=t=>{p({...s,[t.target.name]:t.target.value})},u=async t=>{t.preventDefault();try{m(!0);const a=new FormData;a.append("firstName",s.firstName||""),a.append("email",s.email),a.append("password",s.password);const l=await fetch("/api/sign-up",{method:"POST",body:a}),d=l.headers.get("content-type");if(d&&d.includes("application/json")){const c=await l.json();if(l.ok)r([]),localStorage.setItem("user",JSON.stringify(c)),window.location.href="/";else{const h=c.errors||[{message:"Sign-up failed."}];r(h.map(f=>f.message))}}else r(["Invalid response from the server."])}catch(a){console.error("Error during sign-up:",a),r(["An error occurred. Please try again."])}finally{m(!1)}};return e.jsx("section",{className:"section",children:e.jsx("div",{className:"container",children:e.jsx("div",{className:"row",children:e.jsxs("div",{className:"col-11 sm:col-9 md:col-7 mx-auto",children:[e.jsxs("div",{className:"mb-14 text-center",children:[e.jsx("h2",{className:"max-md:h1 md:mb-2",children:"Create an account"}),e.jsx("p",{className:"md:text-lg",children:"Create an account and start using..."})]}),e.jsxs("form",{onSubmit:u,children:[e.jsxs("div",{children:[e.jsx("label",{className:"form-label",children:"Name"}),e.jsx("input",{name:"firstName",className:"form-input",placeholder:"Enter your name",type:"text",onChange:n,value:s.firstName,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"form-label mt-8",children:"Email Address"}),e.jsx("input",{name:"email",className:"form-input",placeholder:"Type your email",type:"email",onChange:n,value:s.email,required:!0})]}),e.jsxs("div",{children:[e.jsx("label",{className:"form-label mt-8",children:"Password"}),e.jsx("input",{name:"password",className:"form-input",placeholder:"********",type:"password",onChange:n,value:s.password,required:!0})]}),o.length>0&&o.map((t,a)=>e.jsxs("p",{className:"font-medium text-red-500 mt-2",children:["*",t]},a)),e.jsx("button",{type:"submit",className:"btn btn-primary md:text-lg md:font-medium w-full mt-10",children:x?e.jsx(g,{className:"animate-spin mx-auto",size:26}):"Sign Up"})]}),e.jsxs("div",{className:"flex gap-x-2 text-sm md:text-base mt-6",children:[e.jsx("p",{className:"text-light dark:text-darkmode-light",children:"I have read and agree to the"}),e.jsx("a",{className:"underline font-medium text-dark dark:text-darkmode-dark",href:"/terms-services",children:"Terms & Conditions"})]}),e.jsxs("div",{className:"flex gap-x-2 text-sm md:text-base mt-2",children:[e.jsx("p",{className:"text-light dark:text-darkmode-light",children:"Have an account?"}),e.jsx("a",{className:"underline font-medium text-dark dark:text-darkmode-dark",href:"/login",children:"Login"})]})]})})})})};export{y as default};
