{"version":3,"file":"HubSpotFormCreator.PRMk5SXh.mjs","names":["useState","useMemo","useCallback","_window"],"sources":["https:/framerusercontent.com/modules/zD0xrUjkgAVpSm1cgZlm/OMaS0g9T45Sv9ScRCi3Z/HubSpotFormCreator.js"],"sourcesContent":["var _navigator,_window;import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useCallback,useMemo}from\"react\";import{addPropertyControls,ControlType}from\"framer\";const userAgent=(_navigator=navigator)===null||_navigator===void 0?void 0:_navigator.userAgent;const isSafariBrowser=(userAgent===null||userAgent===void 0?void 0:userAgent.includes(\"Safari\"))&&!userAgent.includes(\"Chrome\")||false;const scriptId=\"hbspt-form-script-id\";const scriptURL=\"https://js-eu1.hsforms.net/forms/embed/v2.js\";const hbsptFormIframeClassName=\"hs-form-iframe\";const heightChangeTimerValue=3e3// 3s\n;export function HubSpotFormCreator({portalId,region,formHeight,formId,formHolderDivId,onFormSubmitted}){const[loading,setLoading]=useState(false);const handleLoadEnd=useCallback(()=>{setLoading(false);},[setLoading]);const isNecessaryDataProvided=useMemo(()=>{if(!portalId||!formId||!formHolderDivId||!region){return false;}return true;},[portalId,formId,region,formHolderDivId]);const handleSafariBrowserFormIssue=useCallback(()=>{setTimeout(()=>{var _document;const iframe=(_document=document)===null||_document===void 0?void 0:_document.querySelector(`#${formHolderDivId} .${hbsptFormIframeClassName}`);if(iframe&&(iframe.contentWindow||iframe.contentDocument)){const iframeDocument=iframe.contentWindow.document||iframe.contentDocument;const formElement=iframeDocument===null||iframeDocument===void 0?void 0:iframeDocument.getElementById(`hsForm_${formId}`);if(formElement&&formHeight){formElement.style.height=formHeight;}}},heightChangeTimerValue);},[formId,formHeight,formHolderDivId]);const onFormSubmittedCallback=useCallback(()=>{if(onFormSubmitted){onFormSubmitted();}},[onFormSubmitted]);const createFormAndInsertIntoTargetElement=useCallback(()=>{var _window_hbspt,_window;if((_window=window)===null||_window===void 0?void 0:(_window_hbspt=_window.hbspt)===null||_window_hbspt===void 0?void 0:_window_hbspt.forms){window.hbspt.forms.create({portalId:portalId,region:region,formId:formId,target:`#${formHolderDivId}`,onFormSubmitted:onFormSubmittedCallback});if(isSafariBrowser){handleSafariBrowserFormIssue();}}},[portalId,region,formId,formHolderDivId,onFormSubmittedCallback]);useEffect(()=>{if(isNecessaryDataProvided){var _window;if(!((_window=window)===null||_window===void 0?void 0:_window.document.getElementById(scriptId))){var _window1;if((_window1=window)===null||_window1===void 0?void 0:_window1.document){setLoading(true);const hbsptScript=window.document.createElement(\"script\");hbsptScript.id=scriptId;hbsptScript.src=scriptURL;//hbsptScript.async = true\nwindow.document.body.appendChild(hbsptScript);hbsptScript.onload=()=>{createFormAndInsertIntoTargetElement();setLoading(false);};hbsptScript.onerror=()=>{setLoading(false);};}}else{createFormAndInsertIntoTargetElement();}}},[]);if(!isNecessaryDataProvided){console.error(\"necessary props are not passed to create hubspot form\");return null;}return /*#__PURE__*/_jsx(\"div\",{id:formHolderDivId,style:styles.formContainer,children:loading?/*#__PURE__*/_jsx(\"div\",{style:styles.loader,children:/*#__PURE__*/_jsx(\"div\",{className:\"spinner\"})}):null});}addPropertyControls(HubSpotFormCreator,{portalId:{type:ControlType.String,title:\"portalId\",defaultValue:\"139823521\"},region:{type:ControlType.String,title:\"region\",defaultValue:\"eu1\"},formHeight:{type:ControlType.String,title:\"formHeight\",defaultValue:\"430px\"},formHolderDivId:{type:ControlType.String,title:\"formHolderDivId\"},formId:{type:ControlType.String,title:\"formId\"},onFormSubmitted:{type:ControlType.EventHandler,title:\"onFormSubmit\",defaultValue:\"()=>{}\"}});const styles={formContainer:{height:\"100%\",width:\"100%\",position:\"relative\",overflow:\"auto\"},loader:{position:\"absolute\",top:\"50%\",left:\"50%\",transform:\"translate(-50%, -50%)\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",zIndex:10}};const spinnerStyles=`\n  .spinner {\n    border: 4px solid rgba(0, 0, 0, 0.1);\n    border-left-color: #000;\n    border-radius: 50%;\n    width: 40px;\n    height: 40px;\n    animation: spin 1s linear infinite;\n  }\n\n  @keyframes spin {\n    0% {\n      transform: rotate(0deg);\n    }\n    100% {\n      transform: rotate(360deg);\n    }\n  }\n`;if((_window=window)===null||_window===void 0?void 0:_window.document){const styleSheet=window.document.createElement(\"style\");styleSheet.type=\"text/css\";styleSheet.innerText=spinnerStyles;window.document.head.appendChild(styleSheet);}\nexport const __FramerMetadata__ = {\"exports\":{\"HubSpotFormCreator\":{\"type\":\"reactComponent\",\"name\":\"HubSpotFormCreator\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./HubSpotFormCreator.map"],"mappings":"iVACC,SAAgB,EAAmB,CAAC,WAAS,SAAO,aAAW,SAAO,kBAAgB,mBAAiB,CAAC,GAAK,CAAC,EAAQ,GAAYA,EAAS,GAAM,CAAqB,MAAgB,CAAC,EAAW,GAAM,EAAG,CAAC,EAAW,CAAC,CAAC,IAAM,EAAwBC,MAAa,EAAG,CAAC,GAAU,CAAC,GAAQ,CAAC,GAAiB,CAAC,GAAoC,CAAC,EAAS,EAAO,EAAO,EAAgB,CAAC,CAAO,EAA6BC,MAAgB,CAAC,eAAe,CAAe,IAAM,EAAkB,UAAsD,cAAc,IAAI,EAAgB,IAAI,IAA2B,CAAC,GAAG,IAAS,EAAO,eAAe,EAAO,iBAAiB,CAAC,IAAM,EAAe,EAAO,cAAc,UAAU,EAAO,gBAAsB,EAAY,GAAqE,eAAe,UAAU,IAAS,CAAI,GAAa,IAAY,EAAY,MAAM,OAAO,KAAe,EAAuB,EAAG,CAAC,EAAO,EAAW,EAAgB,CAAC,CAAO,EAAwBA,MAAgB,CAAI,GAAiB,GAAiB,EAAI,CAAC,EAAgB,CAAC,CAAO,EAAqCA,MAAgB,CAAC,IAAkBC,GAAY,EAAQ,IAAU,MAA6CA,EAAQ,OAA2D,QAAO,EAAO,MAAM,MAAM,OAAO,CAAU,WAAgB,SAAc,SAAO,OAAO,IA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