{"version":3,"file":"GainHubSpotFormV2.DPAIIgio.mjs","names":["_Fragment"],"sources":["https:/framerusercontent.com/modules/92r01EpGYWUn7529QPpt/FLyXKKCtELonHIU6wL0b/GainHubSpotFormV2.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef}from\"react\";import{emptyStateStyle}from\"https://framer.com/m/framer/integrations-styles.js@0.2.0\";function poll(f,delay=50,count=50,i=0,errorCallback){if(i>count){errorCallback();return;}if(!f()){setTimeout(()=>{poll(f,delay,count,i+1,errorCallback);},delay);}}function StyleSheet(){return /*#__PURE__*/_jsx(\"style\",{children:`\n            .hs-form-frame {\n                width: 100%;\n            }\n\n            #hubspot_form_tour-lead input[type=\"submit\"] {\n                color: #4d2666 !important;\n                border-radius: 2px !important;\n            }\n\n            `});}/**\n * These annotations control how your component sizes\n * Learn more: https://www.framer.com/docs/guides/auto-sizing\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */export default function GainHubSpotFormV2({portalId,formId,region,containerStyle,id,conversionEvent,handleSubmit,setIsFormReady,oktopostConversion,...props}){const scriptTriggeredRef=useRef(false);if(!portalId||!formId||!region){return /*#__PURE__*/_jsxs(\"div\",{style:{...emptyStateStyle,width:\"100%\",height:\"100%\"},children:[/*#__PURE__*/_jsx(\"h1\",{children:\"Hubspot\"}),/*#__PURE__*/_jsx(\"p\",{children:\"Set a portal ID and form in the Properties.\"})]});}function getUtmParameters(){const params=new URLSearchParams(window.location.search);const utmParams={};// List of standard UTM parameters\nconst standardUtmKeys=[\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_term\",\"utm_content\",\"utm_id\",\"utm_source_platform\",\"utm_creative_format\",\"utm_marketing_tactic\"];standardUtmKeys.forEach(key=>{if(params.has(key)){utmParams[key]=params.get(key);}});return utmParams;}const onPageReady=data=>{setIsFormReady();if(Array.isArray(window.dataLayer)){window.dataLayer.push({event:\"hubspot-form-ready-\"+elementId});}};const onSubmitSuccessful=async event=>{window.HubSpotFormsV4.getForms()[0].getFormFieldValues().then(values=>values);const res=await window.HubSpotFormsV4.getFormFromEvent(event).getFormFieldValues();const currentUtmParams=getUtmParameters();const data=flattenListToObject(res);delete data?.hs_context;delete data?.[\"g-recaptcha-response\"];handleSubmit(data);console.log(data,\"Submitted data\");if(Array.isArray(window.dataLayer)){window.dataLayer.push({event:\"hubspot-form-submitted-\"+elementId,hubspotFormId:formId,currentUtmParams});if(conversionEvent){window.dataLayer.push({event:\"hubspot-form-conversion\",hubspotFormId:formId,conversionEvent:conversionEvent,formData:data});}if(oktopostConversion&&window._oktrk){window._oktrk(\"send\",{tag:oktopostConversion,firstName:data.firstname,lastName:data?.lastname,email:data?.email,company:data?.company});}}};const elementId=`hubspot_form_${id}`;const cleanup=()=>{const element=document.querySelector(`#${elementId}`);if(element){element.innerHTML=\"\";}};function flattenListToObject(list){const result={};for(const item of list){// Remove the \"0-1/\" prefix if it exists\nconst key=item.name.replace(/^0-1\\//,\"\");result[key]=item.value;}return result;}useEffect(()=>{const SCRIPT_ID=\"hubspot-forms-script\";const initializeForm=()=>{handleScriptLoad();};const existingScript=document.getElementById(SCRIPT_ID);if(!existingScript){const script=document.createElement(\"script\");script.id=SCRIPT_ID// Assign the ID\n;script.src=`https://js-${region}.hsforms.net/forms/shell.js`;script.async=true// Load asynchronously to not block rendering\n;script.onload=initializeForm// Call initialization logic when loaded\n;document.body.appendChild(script);}else if(window.hbspt){initializeForm();}else{existingScript.addEventListener(\"load\",initializeForm);}// Attach HubSpot form lifecycle event listeners\nwindow.addEventListener(\"hs-form-event:on-ready\",onPageReady);window.addEventListener(\"hs-form-event:on-submission:success\",onSubmitSuccessful);return()=>{if(existingScript){existingScript.removeEventListener(\"load\",initializeForm);}window.removeEventListener(\"hs-form-event:on-ready\",onPageReady);window.removeEventListener(\"hs-form-event:on-submission:success\",onSubmitSuccessful);};},[]);const handleScriptLoad=()=>{return poll(()=>{if(!window.hbspt){return false;}if(!id||!document.querySelector(`#${elementId}`)){return false;}cleanup();window.hbspt.forms.create({region,portalId,formId,target:`#${elementId}`,formInstanceId:formId});return true;},50,50,0,()=>{if(!window.hbspt){console.warn(`HubSpot could not be loaded: window.hbspt is missing`);return;}if(!document.querySelector(`#${elementId}`)){console.warn(`HubSpot could not be loaded: element not found #${elementId}`);return;}console.warn(`HubSpot could not be loaded: no idea why`);});};return /*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(StyleSheet,{}),/*#__PURE__*/_jsx(\"div\",{id:elementId,style:containerStyle,...props})]});}// Styles are written in object syntax\n// Learn more: https://reactjs.org/docs/dom-elements.html#style\nconst containerStyle={width:\"100%\",height:\"100%\"};GainHubSpotFormV2.displayName=\"General/GainHubSpotFormV2\";GainHubSpotFormV2.defaultProps={portalId:\"5422012\",advanced:false,region:\"na1\",handleSubmit:data=>{},setIsFormReady:()=>{}};addPropertyControls(GainHubSpotFormV2,{// portalId: {\n//     title: \"Portal\",\n//     type: ControlType.String,\n//     placeholder: \"25276298\", // defaultValue: \"25276298\",\n//     description:\n//         \"Create a [Hubspot](https://www.hubspot.com/) account, add a new form and copy your portal ID. [Learn more…](https://www.framer.com/plugins/hubspot/)\",\n// },\nformId:{title:\"Form\",type:ControlType.String,placeholder:\"e7167571-4bc4-4c2c-bfdc-a0a8dbfd22f1\"},conversionEvent:{type:ControlType.String,title:\"Conversion Event\",defaultValue:\"\"},oktopostConversion:{type:ControlType.String,title:\"Oktopost Conversion Event\",defaultValue:\"\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"GainHubSpotFormV2\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./GainHubSpotFormV2.map"],"mappings":"mRAA6P,S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