const MEMBERSTACK_AIRTABLE_ID_FIELD="airtable-record-id",FILLOUT_URL_PARAM_NAME="id";function displayErrorInDiv(div,message){div.innerHTML=`

${message}

`}function loadFilloutEmbedScript(){const filloutScriptSrc="https://server.fillout.com/embed/v1/",existingScript=document.querySelector(`script[src='${filloutScriptSrc}']`);existingScript&&existingScript.remove();const script=document.createElement("script");script.src=filloutScriptSrc,script.async=!0,document.body.appendChild(script)}function initializeFilloutPlaceholders(airtableRecordId){const filloutDivs=document.querySelectorAll("div[fillout-generate]");if(!filloutDivs.length)return;let successfullyProcessedCount=0;filloutDivs.forEach((div,index)=>{const divIdentifier=`Div ${index+1}`,originalUrl=div.getAttribute("source");if(!originalUrl){displayErrorInDiv(div,"Form configuration error: 'source' attribute missing.");return}try{const url=new URL(originalUrl),pathSegments=url.pathname.split("/");let formId=null;const tIndex=pathSegments.indexOf("t");if(tIndex!==-1&&tIndex+10&&loadFilloutEmbedScript()}async function setupDynamicFilloutForms(){const memberstack=window.$memberstackDom;if(!memberstack){document.querySelectorAll("div[fillout-generate]").forEach(div=>{displayErrorInDiv(div,"Initialization error: Memberstack not found on page.")});return}try{const memberData=await memberstack.getCurrentMember();if(!memberData||!memberData.data){document.querySelectorAll("div[fillout-generate]").forEach(div=>{displayErrorInDiv(div,"Please log in to view this form.")});return}const member=memberData.data,airtableRecordId=member.customFields[MEMBERSTACK_AIRTABLE_ID_FIELD];if(!airtableRecordId){document.querySelectorAll("div[fillout-generate]").forEach(div=>{displayErrorInDiv(div,`Your profile is missing necessary information (Ref: ${MEMBERSTACK_AIRTABLE_ID_FIELD}). Please contact support.`)});return}initializeFilloutPlaceholders(airtableRecordId)}catch(error){document.querySelectorAll("div[fillout-generate]").forEach(div=>{displayErrorInDiv(div,"An error occurred while loading your user data. Please try refreshing the page.")})}}window.$memberstackDom?setupDynamicFilloutForms():document.addEventListener("memberstack.ready",function(){setupDynamicFilloutForms()})