{"version":3,"file":"TallyForms.Cl-HZnic.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/jNVNc45FmRe5Gc0wsMUR/WgsEZTjqCgK0IcjD5Zn3/TallyForms.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";import{addPropertyControls,ControlType}from\"framer\";const WIDGET_URL=\"https://tally.so/widgets/embed.js\";/**\n * @framerIntrinsicWidth 700\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight any\n */export default function TallyForms(props){const{form,title,alignLeft,background}=props;const iframeRef=useRef(null);// Use the options to build the URL query params\nconst queryParams=[];queryParams.push(`hideTitle=${title?\"0\":\"1\"}`);queryParams.push(`alignLeft=${alignLeft?\"1\":\"0\"}`);queryParams.push(`transparentBackground=${background?\"0\":\"1\"}`);queryParams.push(\"dynamicHeight=1\");// The iframe URL\nlet embedUrl=\"\";if(form.includes(\"tally.so/\")){// Tally link with form ID\nconst matches=form.match(/\\/(?:r|embed|popup|forms)\\/([a-zA-Z0-9]+)/);if(matches!==null){const formId=matches[1];embedUrl=`https://tally.so/embed/${formId}`;}}else if(form.startsWith(\"http\")&&form.includes(\".\")){// Custom domain\nembedUrl=form;queryParams.push(\"embed=1\");}// If we still don't have URL, we assume the form is the form ID itself\nif(!embedUrl){embedUrl=`https://tally.so/embed/${form}`;}// Append query params\nembedUrl=`${embedUrl}?${queryParams.join(\"&\")}`;const prefillForm=()=>{try{// Get values from URL parameters first\nconst urlParams=new URLSearchParams(window.location.search);let height=urlParams.get(\"height\");let weight=urlParams.get(\"weight\");const mpId=urlParams.get(\"mp_id\")// NEW: Get mp_id from URL\n;// If not in URL, try sessionStorage\nif(!height||!weight){height=sessionStorage.getItem(\"luminaHeight\");weight=sessionStorage.getItem(\"luminaWeight\");}// If still not found, try localStorage\nif(!height||!weight){height=localStorage.getItem(\"luminaHeight\");weight=localStorage.getItem(\"luminaWeight\");}console.log(\"Retrieved values to prefill:\",{height,weight,mpId})// NEW: Log mpId\n;const iframe=iframeRef.current;if(!iframe?.contentWindow){console.log(\"No iframe found\");return;}// Function to fill the form\nconst fillForm=()=>{try{const iframeDoc=iframe.contentDocument||iframe.contentWindow?.document;if(!iframeDoc)return false;// NEW: Add mp_id hidden field ==============================\nlet mpIdInput=iframeDoc.querySelector('input[name=\"mp_id\"]');if(!mpIdInput){mpIdInput=document.createElement(\"input\");mpIdInput.type=\"hidden\";mpIdInput.name=\"mp_id\";iframeDoc.body.appendChild(mpIdInput);console.log(\"Created mp_id hidden field\");}mpIdInput.value=mpId||\"\";// ==========================================================\n// Existing height/weight logic\nconst heightInput=iframeDoc.querySelector('input[placeholder*=\"altura\"], input[name*=\"altura\"]');const weightInput=iframeDoc.querySelector('input[placeholder*=\"peso\"], input[name*=\"peso\"]');if(!heightInput||!weightInput){console.log(\"Inputs not found:\",{heightFound:!!heightInput,weightFound:!!weightInput,mpIdFound:!!mpIdInput});return false;}// Set values with delay\nsetTimeout(()=>{if(height)heightInput.value=height;if(weight)weightInput.value=weight;// Trigger events\nconst events=[\"input\",\"change\",\"keyup\",\"keydown\",\"keypress\",\"focus\",\"blur\"];events.forEach(eventType=>{const event=new Event(eventType,{bubbles:true,cancelable:true,composed:true});heightInput.dispatchEvent(event);weightInput.dispatchEvent(event);});// Add data attributes\nheightInput.setAttribute(\"data-value-set\",height||\"\");weightInput.setAttribute(\"data-value-set\",weight||\"\");},100);console.log(\"Form filled successfully\",{height,weight,mpId});// Clear storage\nsessionStorage.removeItem(\"luminaHeight\");sessionStorage.removeItem(\"luminaWeight\");localStorage.removeItem(\"luminaHeight\");localStorage.removeItem(\"luminaWeight\");return true;}catch(error){console.error(\"Error filling form:\",error);return false;}};// Existing attempt logic\nlet attempts=0;const maxAttempts=20;const attemptInterval=setInterval(()=>{attempts++;console.log(`Attempt ${attempts} to fill form`);if(fillForm()||attempts>=maxAttempts){clearInterval(attemptInterval);}},1e3);setTimeout(()=>clearInterval(attemptInterval),2e4);}catch(error){console.error(\"Error in prefillForm:\",error);}};const loadWidgetScript=()=>{const scriptEl=document.createElement(\"script\");scriptEl.src=WIDGET_URL;scriptEl.onload=()=>{loadEmbeds();prefillForm();};scriptEl.onerror=loadEmbeds;document.body.appendChild(scriptEl);};const loadEmbeds=()=>{const iframeEl=iframeRef.current;if(iframeEl?.dataset?.tallyEmbedWidgetInitialized){iframeEl.removeAttribute(\"data-tally-embed-widget-initialized\");iframeEl.removeAttribute(\"src\");}// @ts-ignore\nif(typeof Tally!==\"undefined\"){// @ts-ignore\nTally.loadEmbeds();}else{document.querySelectorAll(\"iframe[data-tally-src]:not([src])\").forEach(e=>{e.src=e.dataset.tallySrc;});}};useEffect(()=>{// @ts-ignore\nif(typeof Tally!==\"undefined\"){loadEmbeds();prefillForm();}else if(document.querySelector(`script[src=\"${WIDGET_URL}\"]`)==null){loadWidgetScript();}// Also try prefilling when iframe loads\nconst iframe=iframeRef.current;if(iframe){iframe.addEventListener(\"load\",()=>{setTimeout(prefillForm,1e3);});}},[embedUrl]);return /*#__PURE__*/_jsx(\"iframe\",{ref:iframeRef,\"data-tally-src\":embedUrl,\"data-hj-allow-iframe\":\"\",allow:\"cross-origin-isolated\",crossorigin:\"anonymous\",width:\"100%\",height:\"auto\",frameBorder:0,marginHeight:0,marginWidth:0,title:\"Tally form\"});}addPropertyControls(TallyForms,{form:{type:ControlType.String,title:\"Form\",defaultValue:\"tally.so/r/3EKXW4\",description:\"Create a form in [Tally](https://tally.so?ref=framer) and copy the form link\"},title:{type:ControlType.Boolean,title:\"Title\",enabledTitle:\"Show\",disabledTitle:\"Hide\",defaultValue:false},alignLeft:{type:ControlType.Boolean,title:\"Align\",enabledTitle:\"Left\",disabledTitle:\"Center\",defaultValue:true},background:{type:ControlType.Boolean,title:\"Background\",enabledTitle:\"Show\",disabledTitle:\"Hide\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TallyForms\",\"slots\":[],\"annotations\":{\"framer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