{"version":3,"file":"Form.Bfbe-8b7.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/kynWmcNhtQqdjkcslnMB/LGPSt9jGdwNXAScn71IE/Form.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{useEffect,useRef,useState}from\"react\";const UTM_KEYS=[\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_content\",\"utm_term\"];function collectUtms(){const params=new URLSearchParams(window.location.search);const out={};for(const key of UTM_KEYS){const value=params.get(key);if(value)out[key]=value;}return out;}/**\n * TurnStay lead form embed.\n *\n * Height is driven entirely by the form: app/embed/page.tsx runs a\n * ResizeObserver and posts `turnstay:height` (and legacy `RESIZE`) whenever\n * its content changes. Nothing here hardcodes a pixel height.\n *\n * `turnstay:height` is the authoritative one. It measures <body>, the form's\n * real content height. The legacy `RESIZE` measures <html>, which is floored\n * at the iframe's own viewport — and since that viewport is whatever height we\n * last set, it can only ever report the same or more, never less. So RESIZE is\n * a fallback only, until a real measurement arrives.\n *\n * Width: the form's two-column layout is a Tailwind `sm:` breakpoint at 640px,\n * and a media query inside an iframe measures THE IFRAME, not the page. So the\n * iframe's own width decides which layout the form picks, and holding it open\n * to `minWidth` is what keeps two columns on desktop.\n *\n * That floor is applied against the space this component is actually given,\n * not against the device. Keying off window.innerWidth broke phones two ways:\n * it resolves to `false` during SSR, so the published HTML shipped WITH the\n * floor and only dropped it after hydration — by which point the lazy iframe\n * had already laid out at 640 — and the page's width is not the frame's width\n * whenever the frame is fixed-width or padded.\n */export default function TurnStayLeadForm(props){const{baseUrl=\"https://crm.turnstay.com/embed\",minWidth=640}=props;const wrapRef=useRef(null);const iframeRef=useRef(null);const[src,setSrc]=useState(null);// null until the form reports — never a hardcoded height.\nconst[height,setHeight]=useState(null);// Set once the form sends a <body> measurement; from then on the legacy\n// <html> one is ignored, because it can no longer shrink.\nconst haveTrueHeight=useRef(false);// Room the Framer frame actually gives us. null until measured, and no\n// floor is applied while it is null — a phone must never start out wider\n// than its screen, whereas a desktop gaining two columns one frame late\n// costs nothing.\nconst[available,setAvailable]=useState(null);useEffect(()=>{const el=wrapRef.current;if(!el||typeof ResizeObserver===\"undefined\")return;const observer=new ResizeObserver(entries=>{const width=entries[0]&&entries[0].contentRect.width;if(typeof width===\"number\"&&width>0)setAvailable(width);});observer.observe(el);return()=>observer.disconnect();},[]);useEffect(()=>{if(typeof window===\"undefined\")return;const url=new URL(baseUrl);url.searchParams.set(\"parent\",window.location.href);for(const[key,value]of Object.entries(collectUtms())){url.searchParams.set(key,value);}setSrc(url.toString());},[baseUrl]);useEffect(()=>{if(typeof window===\"undefined\")return;function onMessage(event){const frame=iframeRef.current;if(!frame||!event.data||typeof event.data!==\"object\")return;const data=event.data;if(data.type===\"turnstay:request-parent-url\"){if(frame.contentWindow){frame.contentWindow.postMessage({type:\"turnstay:parent-url\",url:window.location.href,...collectUtms()},\"*\");}return;}// The only thing that sets height.\nconst isTrue=data.type===\"turnstay:height\";const isLegacy=data.type===\"RESIZE\";if((isTrue||isLegacy)&&typeof data.height===\"number\"&&data.height>0){// A legacy RESIZE never overrides a real measurement — it\n// cannot report less than the height we already applied, so\n// letting it through would pin the frame at its own value.\nif(isLegacy&&haveTrueHeight.current)return;if(isTrue)haveTrueHeight.current=true;setHeight(data.height);return;}if(data.type===\"FORM_COMPLETE\"){frame.scrollIntoView({behavior:\"smooth\",block:\"start\"});return;}// Application complete — navigate the whole tab. Guarded: must come\n// from OUR iframe, and only to an https turnstay.com destination.\nif(data.type===\"turnstay:redirect\"&&event.source===frame.contentWindow&&typeof data.url===\"string\"){try{const dest=new URL(data.url);const host=dest.hostname;if(dest.protocol===\"https:\"&&(host===\"turnstay.com\"||host.endsWith(\".turnstay.com\"))){window.location.href=dest.toString();}}catch(e){/* malformed URL — ignore */}}}window.addEventListener(\"message\",onMessage);return()=>window.removeEventListener(\"message\",onMessage);},[]);const onLoad=()=>{const frame=iframeRef.current;if(frame&&frame.contentWindow){frame.contentWindow.postMessage({type:\"turnstay:utm\",...collectUtms()},\"*\");}};// Only hold the iframe open when the frame can actually accommodate it.\n// Anything narrower gets no floor, so the iframe matches its container and\n// the form stacks on its own.\nconst floorWidth=available!==null&&available>=minWidth?minWidth:undefined;return /*#__PURE__*/_jsx(\"div\",{ref:wrapRef,style:{width:\"100%\"},children:/*#__PURE__*/_jsx(\"iframe\",{ref:iframeRef,src:src||undefined,onLoad:onLoad,title:\"Apply for TurnStay\",loading:\"lazy\",style:{width:\"100%\",minWidth:floorWidth,height:height!==null?height+\"px\":\"100vh\",border:0,display:\"block\"}})});}addPropertyControls(TurnStayLeadForm,{baseUrl:{type:ControlType.String,title:\"Embed URL\",defaultValue:\"https://crm.turnstay.com/embed\"},minWidth:{type:ControlType.Number,title:\"Min width\",defaultValue:640,min:320,max:1200,description:\"Two columns when the frame is at least this wide; stacked below it\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TurnStayLeadForm\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Form.map"],"mappings":"sMAA+N,SAAS,GAAa,CAAC,IAAM,EAAO,IAAI,gBAAgB,EAAO,SAAS,MAAM,EAAQ,EAAI,CAAC,EAAE,IAAI,IAAM,KAAO,EAAS,CAAC,IAAM,EAAM,EAAO,IAAI,CAAG,EAAK,IAAM,EAAI,GAAK,EAAM,CAAC,OAAO,CAAI,CAwBpZ,SAAwB,EAAiB,EAAM,CAAC,GAAK,CAAC,UAAQ,iCAAiC,WAAS,KAAK,EAAY,EAAQA,EAAO,IAAI,EAAQ,EAAUA,EAAO,IAAI,EAAO,CAAC,EAAI,GAAQC,EAAS,IAAI,EACxM,CAAC,EAAO,GAAWA,EAAS,IAAI,EAE/B,EAAeD,EAAO,EAAK,EAI5B,CAAC,EAAU,GAAcC,EAAS,IAAI,EAS+B,OAT7B,MAAc,CAAC,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