{"version":3,"file":"CustomCalEmbed_BookDemo.ClkyaaSP.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/4RJQiYVIWIMcmGsTy86I/suDd5EVIzXVoV1FaSMEB/CustomCalEmbed_BookDemo.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";// Robust cookie read (handles leading spaces + avoids split edge cases)\nfunction getCookie(name){const match=document.cookie.match(new RegExp(`(?:^|;\\\\s*)${name}=([^;]+)`));return match?decodeURIComponent(match[1]):null;}function getUtmParams(){const cookies=document.cookie.split(\";\");const utmParams={};cookies.forEach(cookie=>{const[name,value]=cookie.trim().split(\"=\");if(name?.startsWith(\"utm_\")&&value!=null){utmParams[name]=decodeURIComponent(value);}});return utmParams;}// Wait until routing is done (or timeout), so Cal reads the final booking_cal_link.\nasync function waitForRoutingDone(maxWaitMs,pollMs){const start=Date.now();while(Date.now()-start<maxWaitMs){const done=getCookie(\"booking_route_done\");if(done===\"1\")return true;await new Promise(r=>setTimeout(r,pollMs));}return false;}export function withCalEmbed(Component){return props=>{const containerRef=useRef(null);useEffect(()=>{if(!containerRef.current)return;let cancelled=false;(async()=>{// Gate Cal initialization so it uses the final calLink cookie.\nconst routedOk=await waitForRoutingDone(2200,50);const email=getCookie(\"booking_email\")??\"\";const utmParams=getUtmParams();// Read selected calLink from cookie (set by CookieFormSubmission override)\nconst routedCalLink=getCookie(\"booking_cal_link\")||\"team/console/enterprise-demo\";const tier=getCookie(\"booking_route_tier\")||\"unknown\";const source=getCookie(\"booking_route_source\")||\"unknown\";console.log(\"Initializing Cal embed with:\",{email,utmParams,routedOk,routedCalLink,tier,source});if(cancelled)return;window.Cal(\"inline\",{elementOrSelector:containerRef.current,config:{layout:\"month_view\",theme:\"light\",email,...utmParams},calLink:routedCalLink});// Optional verification: log the iframe src Cal actually loaded\nsetTimeout(()=>{const src=document.querySelector(\"iframe.cal-embed\")?.getAttribute(\"src\")||null;console.log(\"Cal iframe src:\",src);},250);})();return()=>{cancelled=true;};},[]);// Click outside iframe handler - triggers ESC to let Framer handle close\nuseEffect(()=>{const handleClick=event=>{const iframe=document.querySelector(\"iframe.cal-embed\");if(iframe){const rect=iframe.getBoundingClientRect();const clickX=event.clientX;const clickY=event.clientY;const isOutside=clickX<rect.left||clickX>rect.right||clickY<rect.top||clickY>rect.bottom;if(isOutside){document.dispatchEvent(new KeyboardEvent(\"keydown\",{key:\"Escape\",code:\"Escape\",keyCode:27,which:27,bubbles:true}));}}};const timeoutId=setTimeout(()=>{document.addEventListener(\"mousedown\",handleClick);},100);return()=>{clearTimeout(timeoutId);document.removeEventListener(\"mousedown\",handleClick);};},[]);return /*#__PURE__*/_jsx(Component,{ref:containerRef,...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withCalEmbed\":{\"type\":\"reactHoc\",\"name\":\"withCalEmbed\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./CustomCalEmbed_BookDemo.map"],"mappings":"kIACA,SAAS,EAAU,EAAK,CAAC,IAAM,EAAM,SAAS,OAAO,MAAU,OAAO,cAAc,EAAK,UAAU,CAAC,CAAC,OAAO,EAAM,mBAAmB,EAAM,GAAG,CAAC,KAAM,SAAS,GAAc,CAAC,IAAM,EAAQ,SAAS,OAAO,MAAM,IAAI,CAAO,EAAU,EAAE,CAA6J,OAA5J,EAAQ,QAAQ,GAAQ,CAAC,GAAK,CAAC,EAAK,GAAO,EAAO,MAAM,CAAC,MAAM,IAAI,CAAI,GAAM,WAAW,OAAO,EAAE,GAAO,OAAM,EAAU,GAAM,mBAAmB,EAAM,GAAI,CAAQ,EAC5Y,eAAe,EAAmB,EAAU,EAAO,CAAC,IAAM,EAAM,KAAK,KAAK,CAAC,KAAM,KAAK,KAAK,CAAC,EAAM,GAAU,CAA4C,GAAhC,EAAU,qBAAqB,GAAW,IAAI,MAAO,GAAK,MAAM,IAAI,QAAQ,GAAG,WAAW,EAAE,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