{"version":3,"file":"withPostMessage.BMLPFHZ4.mjs","names":["useCallback"],"sources":["https:/framerusercontent.com/modules/aSKip5BNa5vSDQ8M4GsI/T7FI4N5Naw942RE9MOri/withPostMessage.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{useCallback,useEffect}from\"react\";const isMessageData=data=>{var _this;return((_this=data)===null||_this===void 0?void 0:_this.name)!==undefined;};export function withClickInvoker(Component){return props=>{var _props_dataframername;const name=(_props_dataframername=props[\"data-framer-name\"])!==null&&_props_dataframername!==void 0?_props_dataframername:props[\"name\"];const handleClick=()=>{window.parent.postMessage(JSON.stringify({name}),\"*\");};return /*#__PURE__*/_jsx(Component,{...props,\"data-testid\":`button-${name}`,onClick:handleClick});};}export function withOpenUrl(Component){return props=>{const handleClick=()=>{const url=props[\"href\"];var _props_target;const target=(_props_target=props[\"target\"])!==null&&_props_target!==void 0?_props_target:\"_self\";if(!url){return;}window.parent.postMessage(JSON.stringify({name:\"openUrl\",parameters:{url,target}}),\"*\");};return /*#__PURE__*/_jsx(Component,{...props,onClick:handleClick});};}export function withReceiver(Component){return props=>{const whitelist=[\"http://localhost:3000\",\"https://tutor.qanda-ai.dev\",\"https://tutor-web-test1.qanda-ai.dev\",\"https://tutor-web-test2.qanda-ai.dev\",\"https://tutor.qanda.ai\"];const setInitalData=data=>{try{Object.keys(data).forEach(key=>{const elements=document.querySelectorAll(`[data-framer-name=\"{${key}}\"]`);elements.forEach(element=>{if(element){var _element_getElementsByTagName;const target=(_element_getElementsByTagName=element.getElementsByTagName(\"p\"))===null||_element_getElementsByTagName===void 0?void 0:_element_getElementsByTagName[0];if(target){target.textContent=data[key];}}});});}catch(error){console.log(error);}};const handleMessage=useCallback(event=>{try{if(!whitelist.includes(event.origin)){return;}const data=JSON.parse(event.data);if(!isMessageData(data)){return;}if(data.name===\"setInitalData\"){setInitalData(data.data);}}catch(error){}},[]);useEffect(()=>{window.addEventListener(\"message\",handleMessage);return()=>{window.removeEventListener(\"message\",handleMessage);};},[]);return /*#__PURE__*/_jsx(Component,{...props});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withReceiver\":{\"type\":\"reactHoc\",\"name\":\"withReceiver\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withClickInvoker\":{\"type\":\"reactHoc\",\"name\":\"withClickInvoker\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withOpenUrl\":{\"type\":\"reactHoc\",\"name\":\"withOpenUrl\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./withPostMessage.map"],"mappings":"uIAAqM,SAAgB,EAAiB,EAAU,CAAC,MAAO,IAAO,CAA2B,IAAM,EAA4B,EAAM,qBAAkF,EAAM,KAAc,MAAgB,CAAC,EAAO,OAAO,YAAY,KAAK,UAAU,CAAC,OAAK,CAAC,CAAC,IAAI,EAAG,OAAoB,EAAK,EAAU,CAAC,GAAG,EAAM,cAAc,UAAU,IAAO,QAAQ,EAAY,CAAC,EAA8Y,SAAgB,EAAa,EAAU,CAAC,MAAO,IAAO,CAAC,IAAM,EAAU,CAAC,wBAAwB,6BAA6B,uCAAuC,uCAAuC,yBAAyB,CAAO,EAAc,GAAM,CAAC,GAAG,CAAC,OAAO,KAAK,EAAK,CAAC,QAAQ,GAAK,CAAgB,SAAS,iBAAiB,uBAAuB,EAAI,KAAK,CAAU,QAAQ,GAAS,CAAC,GAAG,EAAQ,CAAmC,IAAM,EAAsC,EAAQ,qBAAqB,IAAI,GAAsF,GAAM,IAAQ,EAAO,YAAY,EAAK,MAAS,EAAG,OAAQ,EAAM,CAAC,QAAQ,IAAI,EAAM,GAAU,EAAcA,EAAY,GAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAU,SAAS,EAAM,OAAO,CAAE,OAAQ,IAAM,EAAK,KAAK,MAAM,EAAM,KAAK,CAAC,GAAG,CAAC,EAAc,EAAK,CAAE,OAAW,EAAK,OAAO,iBAAiB,EAAc,EAAK,KAAK,MAAe,IAAI,EAAE,CAAC,CAAwI,OAAvI,OAAe,EAAO,iBAAiB,UAAU,EAAc,KAAW,CAAC,EAAO,oBAAoB,UAAU,EAAc,GAAK,EAAE,CAAC,CAAqB,EAAK,EAAU,CAAC,GAAG,EAAM,CAAC,yBAAvgE,IAAyC,CAAM,EAAc,GAA+B,GAA0C,OAAQ,IAAA"}