"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),i=require("react"),V=require("../../../../utils/isValidEmail.cjs.js"),O=require("../../../../types/analytics/analytics.cjs.js"),f=require("../../../../src/modules/HSModal/components/Newsletter/newsletter.module.css"),z=require("../../../../components/TextInput/TextInput.cjs.js"),h=require("../../../../components/Button/Button.cjs.js"),A=({buttonText:g,colorScheme:d,onCloseCallback:a,cancelButtonText:S,tags:c,onClickCallback:l,placeholder:x,trackingEvent:p,trackingLocation:T,webhookUrl:j})=>{const[s,m]=i.useState(""),[y,e]=i.useState(!1),[q,t]=i.useState(""),[E,v]=i.useState(!1),[P,o]=i.useState(null),w=n=>{m(n.target.value),y&&(e(!1),t("")),v(n.target.value.length>0)},N=async()=>{var n;if(!s){e(!0),t("Please enter your email address");return}if(!V.isValidEmail(s)){e(!0),t("Please enter a valid email address");return}e(!1),t(""),o("sending");try{const u=c==null?void 0:c.split(",").map(I=>({name:I,status:"active"}));(await fetch(j,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s,tags:u})})).ok?(o("success"),m(""),e(!1),t(""),v(!1),a==null||a()):(o("error"),e(!0),t("Subscription failed. Please try again."))}catch{o("error"),e(!0),t("Subscription failed. Please try again.")}if(l==null||l(),p){const u={event:p,location:T||"",type:O.EAnalyticsEventType.interaction,payload:{email:s,component:"HSModal",element:"Newsletter",pageTitle:document.title}};(n=window.eventBus)==null||n.emit("analytics",u)}},_=d==="light"?"primary":"primary-invert",B=d==="light"?"primary":"primary-invert";return r.jsxs("div",{className:f.interface,children:[r.jsx(z.TextInput,{placeholder:x||"Email",variant:_,value:s,handleChange:w,error:y,errorText:q,active:E}),r.jsxs("div",{className:f.buttonContainer,children:[r.jsx(h.Button,{size:"md",variant:B,onClick:N,children:P==="sending"?"submitting…":g}),r.jsx(h.Button,{size:"md",variant:"ghost",onClick:a,children:S})]})]})};exports.Newsletter=A;
