{"version":3,"file":"SelfCheckContactPrefill.CxB7Sn4U.mjs","names":["useRef"],"sources":["https:/framerusercontent.com/modules/jfBIEql9hML8LvBnpB2D/7GZGuIHxuW6l2WaDK57e/SelfCheckContactPrefill.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{forwardRef,useEffect,useRef}from\"react\";const STORAGE_KEY=\"tc_self_check_handoff_v1\";const NOTICE_ID=\"tc-self-check-prefill-notice\";const MAX_NOTE_LABELS=5;const MAX_NOTE_LENGTH=360;function dispatchFieldEvents(element){element.dispatchEvent(new Event(\"input\",{bubbles:true}));element.dispatchEvent(new Event(\"change\",{bubbles:true}));}function normalizeText(value){return value.trim().toLowerCase();}function parsePayload(raw){if(!raw)return null;try{const parsed=JSON.parse(raw);if(!parsed||typeof parsed!==\"object\")return null;if(typeof parsed.preferredLocation!==\"string\")return null;if(!Array.isArray(parsed.selectedItems))return null;if(typeof parsed.selectedItemCount!==\"number\")return null;if(typeof parsed.sourcePage!==\"string\")return null;if(typeof parsed.createdAt!==\"string\")return null;if(typeof parsed.expiresAt!==\"string\")return null;const expiresMs=Date.parse(parsed.expiresAt);if(!Number.isFinite(expiresMs))return null;if(Date.now()>expiresMs)return null;return{preferredLocation:parsed.preferredLocation,selectedItems:parsed.selectedItems.filter(item=>typeof item===\"string\").map(item=>item.trim()).filter(Boolean),selectedItemCount:parsed.selectedItemCount,sourcePage:parsed.sourcePage,createdAt:parsed.createdAt,expiresAt:parsed.expiresAt};}catch(error){return null;}}function getLabelTextForControl(scope,control){const id=control.id;const texts=[];if(id){const explicit=scope.querySelector(`label[for=\"${id}\"]`);if(explicit?.textContent)texts.push(explicit.textContent);}const wrapping=control.closest(\"label\");if(wrapping?.textContent)texts.push(wrapping.textContent);const ariaLabel=control.getAttribute(\"aria-label\");if(ariaLabel)texts.push(ariaLabel);return normalizeText(texts.join(\" \").trim());}function setSelectToOptionByText(select,desired){const target=normalizeText(desired);if(!target)return false;const options=Array.from(select.options);const match=options.find(option=>normalizeText(option.textContent||option.value)===target);if(!match)return false;if(select.value!==match.value){select.value=match.value;dispatchFieldEvents(select);}return true;}function buildCompactNote(selectedItems){const limited=selectedItems.slice(0,MAX_NOTE_LABELS);const summary=limited.join(\", \");const base=`Completed the T Clinics USA Symptom Self Check. Selected: ${summary||\"none\"}.`;return base.length>MAX_NOTE_LENGTH?`${base.slice(0,MAX_NOTE_LENGTH-1).trimEnd()}…`:base;}export function SelfCheckContactPrefill(Component){return /*#__PURE__*/forwardRef(function SelfCheckContactPrefillOverride(props,ref){const scopeRef=useRef(null);useEffect(()=>{if(typeof window===\"undefined\")return;const scope=scopeRef.current;if(!scope)return;const raw=window.sessionStorage.getItem(STORAGE_KEY);const payload=parsePayload(raw);if(!payload){if(raw!==null){try{window.sessionStorage.removeItem(STORAGE_KEY);}catch(error){// Ignore storage cleanup errors.\n}}return;}const form=scope.querySelector(\"form\");if(!form)return;// Location prefill.\nconst allSelects=Array.from(form.querySelectorAll(\"select\"));const locationSelect=allSelects.find(select=>{const text=normalizeText(`${select.name} ${select.id} ${getLabelTextForControl(scope,select)}`);return text.includes(\"location\");});if(locationSelect&&locationSelect.value===\"\"&&payload.preferredLocation){setSelectToOptionByText(locationSelect,payload.preferredLocation);}// Optional note / textarea.\nconst textareas=Array.from(form.querySelectorAll(\"textarea\"));const noteTarget=textareas.find(textarea=>{const text=normalizeText(`${textarea.name} ${textarea.id} ${textarea.placeholder||\"\"} ${getLabelTextForControl(scope,textarea)}`);return text.includes(\"note\")||text.includes(\"message\")||text.includes(\"anything else\")||text.includes(\"anything you'd like\")||text.includes(\"additional\");});if(noteTarget&&noteTarget.value.trim()===\"\"){noteTarget.value=buildCompactNote(payload.selectedItems);dispatchFieldEvents(noteTarget);}// Insert compact notice once, immediately before the form.\nconst existingNotice=scope.querySelector(`[data-${NOTICE_ID}=\"true\"]`);if(!existingNotice){const notice=document.createElement(\"div\");notice.setAttribute(`data-${NOTICE_ID}`,\"true\");notice.setAttribute(\"role\",\"status\");notice.setAttribute(\"aria-live\",\"polite\");notice.style.boxSizing=\"border-box\";notice.style.width=\"100%\";notice.style.maxWidth=\"100%\";notice.style.margin=\"0 0 12px 0\";notice.style.padding=\"10px 12px\";notice.style.border=\"1px solid rgba(0, 0, 0, 0.12)\";notice.style.borderRadius=\"10px\";notice.style.background=\"rgba(0, 0, 0, 0.03)\";notice.style.overflowWrap=\"break-word\";notice.style.wordBreak=\"normal\";const eyebrow=document.createElement(\"p\");eyebrow.textContent=\"YOUR SELF CHECK IS COMPLETE\";eyebrow.style.margin=\"0\";eyebrow.style.fontSize=\"11px\";eyebrow.style.letterSpacing=\"0.08em\";eyebrow.style.textTransform=\"uppercase\";eyebrow.style.fontWeight=\"700\";eyebrow.style.lineHeight=\"1.3\";const body=document.createElement(\"p\");body.textContent=\"We carried your selections forward so you don’t have to start over. Add your contact information below and send your consultation request when you’re ready.\";body.style.margin=\"6px 0 0\";body.style.fontSize=\"13px\";body.style.lineHeight=\"1.4\";notice.appendChild(eyebrow);notice.appendChild(body);form.parentElement?.insertBefore(notice,form);}},[]);return /*#__PURE__*/_jsx(\"div\",{ref:scopeRef,style:{position:\"relative\",width:\"100%\",minWidth:0},children:/*#__PURE__*/_jsx(Component,{ref:ref,...props,style:{...props.style}})});});}\nexport const __FramerMetadata__ = {\"exports\":{\"SelfCheckContactPrefill\":{\"type\":\"reactHoc\",\"name\":\"SelfCheckContactPrefill\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SelfCheckContactPrefill.map"],"mappings":"8IAAwO,SAAS,EAAoB,EAAQ,CAAC,EAAQ,cAAc,IAAI,MAAM,QAAQ,CAAC,QAAQ,EAAI,CAAC,CAAC,EAAE,EAAQ,cAAc,IAAI,MAAM,SAAS,CAAC,QAAQ,EAAI,CAAC,CAAC,CAAE,CAAC,SAAS,EAAc,EAAM,CAAC,OAAO,EAAM,KAAK,CAAC,CAAC,YAAY,CAAE,CAAC,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