{"version":3,"file":"HSFormComponent.4aWHStc0.mjs","names":["useRef","useState","formId"],"sources":["https:/framerusercontent.com/modules/TvBzOsGLcWPVNcfiqnKB/IwT6RsbAfh6tmOMmuWBV/HSFormComponent.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useState,useRef}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import styled,{keyframes}from\"styled-components\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */export default function HubSpotFormComponent(props){const{portalId,formId,region=\"na1\",onSubmitted,testMode=false}=props;const formContainerRef=useRef(null);const[formLoaded,setFormLoaded]=useState(false);const[scriptLoaded,setScriptLoaded]=useState(false);const testIntervalRef=useRef(null);// Load HubSpot Forms script\nuseEffect(()=>{if(document.getElementById(\"hubspot-form-script\")){setScriptLoaded(true);return;}const script=document.createElement(\"script\");script.id=\"hubspot-form-script\";script.src=`https://js.hsforms.net/forms/embed/v2.js`;script.charset=\"utf-8\";script.async=true;script.onload=()=>{console.log(\"HubSpot Forms script loaded\");setScriptLoaded(true);};document.head.appendChild(script);return()=>{// We don't remove the script on unmount because other instances may need it\n};},[region]);// Create form once script is loaded\nuseEffect(()=>{if(!scriptLoaded||!formContainerRef.current)return;// Clear previous form if any\nif(formContainerRef.current.firstChild){formContainerRef.current.innerHTML=\"\";}const handleFormLoaded=()=>{const{formId,instanceId}=event.detail;setFormLoaded(true);console.log(\"hs-form-event:on-ready\",formId,event.detail);};const handleFormSubmit=()=>{try{const formInstance=window.HubspotFormsV4.getFormFromEvent(event);console.log(\"hs-form-event:on-submission:success\",formId,formInstance);// Push to dataLayer for GTM\nif(window.dataLayer){window.dataLayer.push({event:\"hubspot_form_submission\",formId:formInstance?.getFormId()??\"\",formTarget:formInstance?.getInstanceId()??\"\"});}}catch(e){console.error(e);}console.log(\"hs-form-event:on-submission:success\",formId,event.detail);};window.addEventListener(\"hs-form-event:on-ready\",handleFormLoaded);window.addEventListener(\"hs-form-event:on-submission:success\",handleFormSubmit);// Create form\nif(window.hbspt){console.log(\"Creating HubSpot form:\",portalId,formId);window.hbspt.forms.create({region:region,portalId:portalId,formId:formId,target:`#hubspot-form-container-${formId}`});}return()=>{window.removeEventListener(\"message\",handleFormEvent);window.removeEventListener(\"hs-form-event:on-ready\",handleFormLoaded);window.removeEventListener(\"hs-form-event:on-submission:success\",handleFormSubmit);};},[scriptLoaded,portalId,formId,region,onSubmitted]);// Handle HubSpot form messages/events\nconst handleFormEvent=event1=>{const data=event1.data;if(typeof data!==\"object\")return;if(data.type===\"hsFormCallback\"&&data.eventName===\"onFormSubmitted\"&&data.id===formId){console.log(\"Form submission event received:\",data);// Push to dataLayer for GTM\nif(window.dataLayer){window.dataLayer.push({event:\"hubspot_form_submission\",formId:data.id,submissionValues:data.data?.submissionValues||{}});}// Call the onSubmitted handler\nif(onSubmitted){onSubmitted(data.data);}}};return /*#__PURE__*/_jsxs(FormContainer,{children:[!scriptLoaded||!formLoaded&&/*#__PURE__*/_jsx(Loading,{\"aria-label\":\"Loading...\",children:/*#__PURE__*/_jsx(\"div\",{})}),/*#__PURE__*/_jsx(\"div\",{id:`hubspot-form-container-${formId}`,ref:formContainerRef,style:{display:formLoaded?\"block\":\"none\"}})]});}const FormContainer=styled.div`\n    width: 100%;\n    min-height: 100px;\n    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n`;const FormFieldsContainer=styled.div`\n    width: 100%;\n`;const anime=keyframes`\n    90%,100% {box-shadow: -10px 0,10px 0,0 10px, 0 -10px;transform: rotate(180deg)}\n`;const Loading=styled.div`\n  position: fixed;\n  left: 0;\n  top: 0;\n  width: 100%;\n  height: 100%;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n    \n\n  div {\n    width: 100px;\n    aspect-ratio: 1;\n    padding: 10px;\n    box-sizing: border-box;\n    display: grid;\n    background: #fff;\n    filter: blur(3px) contrast(7) hue-rotate(180deg);\n    mix-blend-mode: darken;\n}\n\ndiv:before {\n    content: \"\";\n    margin: auto;\n    width: 30px;\n    height: 30px;\n    border-radius: 50%;\n    color: #000000;\n    background: currentColor;\n    box-shadow: -30px 0, 30px 0, 0 30px, 0 -30px;\n    animation: ${anime} 1s infinite alternate;\n}\n\n\n`;HubSpotFormComponent.defaultProps={region:\"na1\",testMode:false};addPropertyControls(HubSpotFormComponent,{portalId:{type:ControlType.String,title:\"Portal ID\",description:\"HubSpot Portal ID\"},formId:{type:ControlType.String,title:\"Form ID\",description:\"HubSpot Form ID\"},region:{type:ControlType.Enum,title:\"Region\",options:[\"na1\",\"eu1\"],optionTitles:[\"North America\",\"Europe\"],defaultValue:\"na1\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"HubSpotFormComponent\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./HSFormComponent.map"],"mappings":"mbAGG,SAAwB,EAAqB,EAAM,CAAC,GAAK,CAAC,WAAS,SAAO,SAAO,MAAM,cAAY,WAAS,IAAO,EAAY,EAAiBA,EAAO,KAAK,CAAM,CAAC,EAAW,GAAeC,EAAS,GAAM,CAAM,CAAC,EAAa,GAAiBA,EAAS,GAAM,CAAuB,EAAO,KAAK,CACtS,MAAc,CAAC,GAAG,SAAS,eAAe,sBAAsB,CAAC,CAAC,EAAgB,GAAK,CAAC,OAAQ,IAAM,EAAO,SAAS,cAAc,SAAS,CAAwP,MAAvP,GAAO,GAAG,sBAAsB,EAAO,IAAI,2CAA2C,EAAO,QAAQ,QAAQ,EAAO,MAAM,GAAK,EAAO,WAAW,CAAC,QAAQ,IAAI,8BAA8B,CAAC,EAAgB,GAAK,EAAG,SAAS,KAAK,YAAY,EAAO,KAAW,IAC3Y,CAAC,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