"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("react"),x=require("../../../../utils/cn/cn.cjs.js"),S=require("../../../../utils/isValidEmail.cjs.js"),s=require("../../../../src/pageComponents/Footer/components/NewsLetter/newsLetter.module.css"),u=require("../../../../components/Typography/Typography.cjs.js"),T=require("../../../../components/TextInput/TextInput.cjs.js"),j="https://hook.us2.make.com/t87e9ij5ebvcoqeushd45ihubsghratq",w=({onSubmit:c})=>{const[r,d]=i.useState(""),[y,g]=i.useState(""),[h,t]=i.useState(!1),[m,a]=i.useState(""),[b,p]=i.useState(!1),[n,l]=i.useState(null),f=o=>{d(o.target.value),h&&(t(!1),a("")),p(o.target.value.length>0)},v=async()=>{if(!r){t(!0),a("Please enter your email address");return}if(!S.isValidEmail(r)){t(!0),a("Please enter a valid email address");return}t(!1),a(""),l("sending");try{(await fetch(j,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:r})})).ok?(l("success"),g(r),d(""),t(!1),a(""),p(!1),c==null||c(r)):(l("error"),t(!0),a("Subscription failed. Please try again."))}catch{l("error"),t(!0),a("Subscription failed. Please try again.")}};return e.jsxs("div",{className:x.cn(s.root,{[s.subscribed]:n==="success"}),children:[e.jsxs("div",{className:s.container,children:[e.jsx(u.Typography,{defaultVariant:"headingLg",mobileVariant:"headingSm",as:"h2",className:s.title,children:n==="success"?"Thanks for subscribing!":"Read the latest research reviews"}),e.jsx(u.Typography,{defaultVariant:"bodySm",mobileVariant:"bodyXs",as:"span",className:s.text,children:n==="success"?e.jsxs(e.Fragment,{children:["You will now begin receiving our monthly newsletter at"," ",e.jsx("b",{className:s.email,children:y}),". It's a great way to keep up to date on the latest developments in longevity science."]}):"Request The Longevity Blueprint to receive our weekly newsletter containing synopses of the latest clinical research."})]}),n==="sending"&&e.jsx("div",{className:s.container,children:e.jsx(u.Typography,{defaultVariant:"bodySm",mobileVariant:"bodyXs",as:"span",className:s.text,children:"Subscribing, please wait..."})}),n!=="success"&&n!=="sending"&&e.jsx(T.TextInput,{placeholder:"Your email",variant:"primary-invert",value:r,handleChange:f,onButtonClick:v,showButton:!0,error:h,errorText:m,active:b})]})};exports.NewsLetter=w;
