{"version":3,"file":"NewsletterWidget.ChEfxo7A.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/Gb0UAaVC9Ek8gavXZUMK/bAJHiAcaQBkdNSGjaP9k/NewsletterWidget.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useState,useEffect}from\"react\";export default function NewsletterWidget(props){const[email,setEmail]=useState(\"\");const[status,setStatus]=useState(\"idle\");const[isNarrow,setIsNarrow]=useState(false);useEffect(()=>{const breakpoint=props.stackBelow||480;const mq=window.matchMedia(`(max-width: ${breakpoint}px)`);const handler=e=>setIsNarrow(e.matches);handler(mq);if(mq.addEventListener)mq.addEventListener(\"change\",handler);else mq.addListener(handler);return()=>{if(mq.removeEventListener)mq.removeEventListener(\"change\",handler);else mq.removeListener(handler);};},[props.stackBelow]);const handleSubmit=async e=>{e.preventDefault();if(!email.includes(\"@\"))return;setStatus(\"loading\");try{await fetch(`https://${props.substackSub}.substack.com/api/v1/free`,{method:\"POST\",headers:{\"Content-Type\":\"application/json\"},mode:\"no-cors\",body:JSON.stringify({email:email.trim().toLowerCase(),first_url:window.location.href,first_referrer:document.referrer,current_url:window.location.href,current_referrer:document.referrer})});const emailHashed=await sha256(email.trim().toLowerCase());window.dataLayer=window.dataLayer||[];window.dataLayer.push({event:\"newsletter_signup\",email_hashed:emailHashed,substack_publication:props.publicationSlug||props.substackSub});setStatus(\"success\");setEmail(\"\");}catch(err){console.error(\"Newsletter signup failed:\",err);setStatus(\"error\");}};if(status===\"success\"){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"flex\",justifyContent:\"center\",alignItems:\"center\",padding:\"16px 20px\",width:\"100%\",minHeight:56,background:props.bgColor,borderRadius:10,border:`2px solid ${props.brandColor}`,boxSizing:\"border-box\"},children:/*#__PURE__*/_jsx(\"p\",{style:{fontFamily:\"Public Sans, sans-serif\",fontSize:15,color:props.brandColor,margin:0,fontWeight:600,textAlign:\"center\"},children:props.successText})});}const inputStyle={flex:1,minWidth:0,width:\"100%\",padding:\"14px 18px\",fontSize:16,fontFamily:\"Public Sans, sans-serif\",border:`2px solid ${props.brandColor}`,borderRight:isNarrow?`2px solid ${props.brandColor}`:\"none\",borderRadius:isNarrow?10:\"10px 0 0 10px\",outline:\"none\",background:props.bgColor,color:props.textColor,boxSizing:\"border-box\",minHeight:50};const buttonStyle={padding:\"14px 22px\",fontSize:15,fontWeight:600,fontFamily:\"Public Sans, sans-serif\",color:props.textColor,background:props.brandColor,border:\"none\",borderRadius:isNarrow?10:\"0 10px 10px 0\",cursor:\"pointer\",opacity:status===\"loading\"?.6:1,whiteSpace:\"nowrap\",minHeight:isNarrow?50:50,width:isNarrow?\"100%\":\"auto\",boxSizing:\"border-box\"};return /*#__PURE__*/_jsxs(\"form\",{onSubmit:handleSubmit,style:{display:\"flex\",flexDirection:isNarrow?\"column\":\"row\",gap:isNarrow?10:0,width:\"100%\",maxWidth:480,boxSizing:\"border-box\"},children:[/*#__PURE__*/_jsx(\"input\",{type:\"email\",required:true,placeholder:props.placeholder,value:email,onChange:e=>setEmail(e.target.value),disabled:status===\"loading\",style:inputStyle}),/*#__PURE__*/_jsx(\"button\",{type:\"submit\",disabled:status===\"loading\",style:buttonStyle,children:status===\"loading\"?\"...\":props.buttonText})]});}async function sha256(s){const buf=new TextEncoder().encode(s);const hash=await crypto.subtle.digest(\"SHA-256\",buf);return Array.from(new Uint8Array(hash)).map(b=>b.toString(16).padStart(2,\"0\")).join(\"\");}addPropertyControls(NewsletterWidget,{substackSub:{type:ControlType.String,title:\"Substack subdomain\",defaultValue:\"ctrlai\",description:\"ctrlai.substack.com (= controlai.news custom domain)\"},publicationSlug:{type:ControlType.String,title:\"Pub slug (tracking)\",defaultValue:\"ctrlai\",description:\"Sent to dataLayer.substack_publication\"},placeholder:{type:ControlType.String,title:\"Placeholder\",defaultValue:\"Enter your email\"},buttonText:{type:ControlType.String,title:\"Button\",defaultValue:\"Join the Campaign\"},successText:{type:ControlType.String,title:\"Success message\",defaultValue:\"Thanks! Check your inbox to confirm.\"},brandColor:{type:ControlType.Color,title:\"Brand color\",defaultValue:\"#00DEB6\"},textColor:{type:ControlType.Color,title:\"Text color\",defaultValue:\"#222937\"},bgColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFC\"},stackBelow:{type:ControlType.Number,title:\"Stack below (px)\",defaultValue:480,min:320,max:1024,step:10,description:\"Viewport width under which input + button stack vertically\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NewsletterWidget\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./NewsletterWidget.map"],"mappings":"uMAAmJ,SAAwB,EAAiB,EAAM,CAAC,GAAK,CAAC,EAAM,GAAUA,EAAS,GAAG,CAAM,CAAC,EAAO,GAAWA,EAAS,OAAO,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAM,CAAC,MAAc,CAAC,IAAM,EAAW,EAAM,YAAY,IAAU,EAAG,EAAO,WAAW,eAAe,EAAW,KAAK,CAAO,EAAQ,GAAG,EAAY,EAAE,QAAQ,CAAuG,OAAtG,EAAQ,EAAG,CAAI,EAAG,iBAAiB,EAAG,iBAAiB,SAAS,EAAQ,CAAM,EAAG,YAAY,EAAQ,KAAW,CAAI,EAAG,oBAAoB,EAAG,oBAAoB,SAAS,EAAQ,CAAM,EAAG,eAAe,EAAQ,GAAK,CAAC,EAAM,WAAW,CAAC,CAAC,IAAM,EAAa,KAAM,IAAG,CAAC,KAAE,gBAAgB,CAAK,EAAM,SAAS,IAAI,CAAQ,GAAU,UAAU,CAAC,GAAG,CAAC,MAAM,MAAM,WAAW,EAAM,YAAY,2BAA2B,CAAC,OAAO,OAAO,QAAQ,CAAC,eAAe,mBAAmB,CAAC,KAAK,UAAU,KAAK,KAAK,UAAU,CAAC,MAAM,EAAM,MAAM,CAAC,aAAa,CAAC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