{"version":3,"file":"Hubspot.STda88wf.mjs","names":["React.useState","React.useRef","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","window","ce","init_jsx_runtime","c","p","_e","de","useTracking","addPropertyControls","ControlType","init_framer_Bf4_tcb2","init_integrations_styles_js_0_2","stateParagraphStyle","stateTitleStyle","emptyStateStyle","poll","i","count","f","delay","EmptyState","title","description","getActualInstanceId","url","div","HubSpotForm","isScriptLoaded","setIsScriptLoaded","ref","track","portalId","formId","trackingId","onFormSubmissionSuccess","event","region","script","element","elementId","init_Hubspot","advanced"],"sources":["https:/framerusercontent.com/modules/uGQZtcsxBzvxqsgxQ0Tz/x1uX2pQ17kYOWs5UPyT3/Hubspot.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import*as React from\"react\";import{addPropertyControls,ControlType,useTracking}from\"framer\";import{emptyStateStyle,stateParagraphStyle,stateTitleStyle}from\"https://framer.com/m/framer/integrations-styles.js@0.2.0\";// Poll for 5 minutes ...\nfunction poll(f,delay=200,count=5*60*5,i=0){if(i>count){console.error(\"poll max attempts\",f);return;}if(!f()){console.log(\"poll\",delay,count,i);setTimeout(()=>{poll(f,delay,count,i+1);},delay);}}function EmptyState({title,description}){return /*#__PURE__*/_jsxs(\"div\",{style:{...emptyStateStyle,width:\"100%\",height:\"100%\"},children:[/*#__PURE__*/_jsx(\"h1\",{style:stateTitleStyle,children:title}),/*#__PURE__*/_jsx(\"p\",{style:stateParagraphStyle,children:description})]});}/**\n * Return the actual instance id of the HubSpot form.\n *\n * window.hbspt.forms.create returns a totally different instanceId\n * from the one in the success event. This ugly code below grabs the\n * actual instance id from the iframe src. Hopefully this doesn’t break.\n */function getActualInstanceId(div){const url=div.querySelector(\"iframe\")?.getAttribute(\"src\");return url?new URL(url).searchParams.get(\"_hsInstanceId\"):null;}/**\n * HUBSPOT\n *\n * @framerIntrinsicWidth 480\n * @framerIntrinsicHeight 300\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight auto\n */export default function HubSpotForm({portalId,formId,advanced,region,trackingId}){const[isScriptLoaded,setIsScriptLoaded]=React.useState(()=>Boolean(typeof window!==\"undefined\"&&window.hbspt));const ref=React.useRef(null);const track=useTracking();// Tracking setup\nReact.useEffect(()=>{if(!portalId||!formId||!trackingId)return;function onFormSubmissionSuccess(event){if(!ref.current)return;// Because the events are global, we need to compare\n// instanceId to know which instance it is comes from.\nif(getActualInstanceId(ref.current)!==event.detail.instanceId)return;if(trackingId)track(trackingId);}// https://developers.hubspot.com/docs/guides/api/marketing/forms/global-form-events#form-events$0\ndocument.addEventListener(\"hs-form-event:on-submission:success\",onFormSubmissionSuccess);return()=>document.removeEventListener(\"hs-form-event:on-submission:success\",onFormSubmissionSuccess);},[trackingId,formId,portalId]);// Load the hubspot script\nReact.useEffect(()=>{if(!region)return;if(isScriptLoaded||typeof window===\"undefined\")return;if(window.hbspt)return setIsScriptLoaded(true);const script=document.createElement(\"script\");script.src=`https://js-${region}.hsforms.net/forms/shell.js`;script.async=true;script.onload=()=>poll(()=>{if(window.hbspt){setIsScriptLoaded(true);return true;}});document.body.appendChild(script);},[isScriptLoaded,region]);React.useEffect(()=>{if(!portalId||!formId)return;if(!isScriptLoaded||!ref.current||typeof window===\"undefined\")return;const element=document.createElement(\"div\");const randomId=Math.random().toString(36).substr(2,8);const elementId=`hubspot_form_${randomId}`;element.setAttribute(\"id\",elementId);element.style.width=\"100%\";element.style.height=\"100%\";ref.current.appendChild(element);window.hbspt.forms.create({region,portalId,formId,target:`#${elementId}`});return()=>{if(ref.current)ref.current.removeChild(element);};},[isScriptLoaded,portalId,formId]);if(!portalId||!formId||!region){return /*#__PURE__*/_jsx(EmptyState,{title:\"Hubspot\",description:\"Set a portal ID and form in the Properties.\"});}return /*#__PURE__*/_jsx(\"div\",{style:{display:\"contents\"},ref:ref});}addPropertyControls(HubSpotForm,{portalId:{title:\"Portal\",type:ControlType.String,placeholder:\"25276298\",// defaultValue: \"25276298\",\ndescription:\"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/)\"},formId:{title:\"Form\",type:ControlType.String,placeholder:\"e7167571-4bc4-4c2c-bfdc-a0a8dbfd22f1\"},trackingId:{title:\"Tracking\",type:ControlType.TrackingId,placeholder:\"ID\"},advanced:{title:\"Advanced\",type:ControlType.Boolean,enabledTitle:\"Show\",disabledTitle:\"Hide\",defaultValue:false},region:{title:\"Region\",type:ControlType.String,placeholder:\"eu1\",defaultValue:\"eu1\",hidden:({advanced})=>!advanced}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"HubSpotForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"300\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerSupportedLayoutHeight\":\"auto\",\"framerIntrinsicWidth\":\"480\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Hubspot.map"],"mappings":"A,oRACA,SAASoB,EAAK,EAAE,EAAM,IAAI,EAAM,KAAO,EAAE,EAAE,CAAIC,EAAEC,EAAO,QAAQ,MAAM,oBAAoBC,CAAC,EAAcA,EAAE,IAAG,QAAQ,IAAI,OAAOC,EAAMF,EAAMD,CAAC,EAAE,eAAe,CAACD,EAAKG,EAAEC,EAAMF,EAAMD,EAAE,CAAC,CAAE,EAAEG,CAAK,EAAG,CAAC,SAASC,EAAW,CAAC,QAAM,eAAa,CAAC,MAAoB,gBAAM,MAAM,CAAC,MAAM,CAAC,GAAGN,EAAgB,MAAM,OAAO,OAAO,MAAM,EAAE,SAAS,CAAc,gBAAK,KAAK,CAAC,MAAMD,EAAgB,SAASQ,CAAK,CAAC,EAAe,gBAAK,IAAI,CAAC,MAAMT,EAAoB,SAASU,CAAW,CAAC,CAAC,CAAC,CAAC,CAAE,CAMpd,SAASC,EAAoB,EAAI,CAAC,IAAMC,EAAIC,EAAI,cAAc,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