{"version":3,"file":"GainHubSpotFormV2.BH6_o7qQ.mjs","names":["_Fragment"],"sources":["https:/framerusercontent.com/modules/92r01EpGYWUn7529QPpt/g9cfBWN3NxDARob4yZkH/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 * 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.\"})]});}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(()=>{if(window.hbspt){handleScriptLoad();return cleanup;}const script=document.createElement(\"script\");script.src=`https://js-${region}.hsforms.net/forms/shell.js`;script.onload=handleScriptLoad;document.body.appendChild(script);scriptTriggeredRef.current=true;window.addEventListener(\"hs-form-event:on-ready\",data=>{setIsFormReady();if(Array.isArray(window.dataLayer)){window.dataLayer.push({event:\"hubspot-form-ready-\"+elementId});}});window.addEventListener(\"hs-form-event:on-submission:success\",async event=>{window.HubSpotFormsV4.getForms()[0].getFormFieldValues().then(values=>values);const res=await window.HubSpotFormsV4.getFormFromEvent(event).getFormFieldValues();const data=flattenListToObject(res);delete data?.hs_context;delete data?.[\"g-recaptcha-response\"];handleSubmit(data);if(Array.isArray(window.dataLayer)){window.dataLayer.push({event:\"hubspot-form-submitted-\"+elementId,hubspotFormId:formId});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});}}});return cleanup;},[formId]);const handleScriptLoad=()=>{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\":{\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./GainHubSpotFormV2.map"],"mappings":"6ZAA6P,SAAS,EAAK,EAAE,EAAM,GAAG,EAAM,GAAG,EAAE,EAAE,EAAc,CAAC,GAAG,EAAE,EAAM,CAAC,GAAe,CAAC,MAAQ,CAAI,GAAG,EAAE,WAAW,IAAI,CAAC,EAAK,EAAE,EAAM,EAAM,EAAE,EAAE,EAAc,AAAE,EAAC,EAAM,AAAG,UAAS,GAAY,CAAC,MAAoB,GAAK,QAAQ,CAAC,SAAA;;;;aAI1c,EAAC,AAAE,CAMd,SAAwB,EAAkB,CAAC,WAAS,SAAO,SAAO,iBAAe,KAAG,kBAAgB,eAAa,iBAAe,qBAAmB,GAAG,EAAM,CAAC,CAAC,IAAM,EAAmB,GAAO,EAAM,CAAC,IAAI,IAAW,IAAS,EAAQ,MAAoB,GAAM,MAAM,CAAC,MAAM,CAAC,GAAG,EAAgB,MAAM,OAAO,OAAO,MAAO,EAAC,SAAS,CAAc,EAAK,KAAK,CAAC,SAAS,SAAU,EAAC,CAAc,EAAK,IAAI,CAAC,SAAS,6CAA8C,EAAC,AAAC,CAAC,EAAC,CAAE,IAAM,GAAW,eAAe,IAAW,EAAQ,IAAI,CAAC,IAAM,EAAQ,SAAS,eAAe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