(()=>{const e="https://face.viasocket.com/i";let t=null,n=!1;const o="interfaceData";let a={};const i=d("b1357e23-2fc6-4dc3-855a-7a213b1fa100"),c=d("91ee0bff-cfe3-4e2d-64e5-fadbd9a3a200"),r=document.getElementById("interface-main-script");function d(e){return`https://imagedelivery.net/Vv7GgOGQbSyClWJqhyP0VQ/${e}/public`}r?["interfaceId","embedToken","threadId","bridgeName","variables","onOpen","onClose","theme","className","style","environment","fullScreen"].forEach((e=>{r.hasAttribute(e)&&(a[e]=r.getAttribute(e))})):console.log("Script tag not found"),closeIframe=function(){if("block"===document.getElementById("iframe-parent-container")?.style?.display)return document.getElementById("iframe-parent-container").style.display="none",document.body.style.overflow="auto",document.getElementById("interfaceEmbed").style.display="unset",void window.parent?.postMessage({type:"close",data:{}},"*")};const l=e=>{a={...a,...e},m(e)},m=e=>{e.theme?document.getElementById("popup-interfaceEmbed").src="proxy.php?url=dark"===e.theme?i:c:!0===e.fullScreen||"true"===e.fullScreen?document.getElementById("iframe-parent-container")?.classList.add("full-screen"):!1!==e.fullScreen&&"false"!==e.fullScreen||document.getElementById("iframe-parent-container")?.classList.remove("full-screen")},s=setTimeout((()=>{window.removeEventListener("message",f),console.log("Event listener removed after 60 seconds")}),6e4);function f(e){const{type:n}=e.data;"interfaceLoaded"===n&&(t&&(console.log("data sent"),document.getElementById("iframe-component").contentWindow.postMessage({type:o,data:t},"*"),t=null),window.removeEventListener("message",f),clearTimeout(s),console.log("interfaceLoaded and event listener removed"))}loadContent=function(){if(!n){window.addEventListener("message",f);var e=document.createElement("link");if(e.rel="stylesheet",e.type="text/css",e.href="proxy.php?url=https://interface-embed.viasocket.com/style-prod.css",document.head.appendChild(e),document.getElementById("iframe-parent-container"))closeIframe(),document.getElementById("iframe-component")&&(document.getElementById("iframe-component").src="proxy.php?url=");else{const e=document.createElement("div");e.id="iframe-parent-container",e.className="popup-parent-container",e.style.display="none",e.innerHTML='\n \n \n ';const t=document.createElement("div");t.id="interfaceEmbed";const n=document.createElement("img");n.id="popup-interfaceEmbed",n.className="chatbot-icon",n.alt="Ask Ai",n.src=c,t.appendChild(n),document.body.appendChild(t),document.getElementById("interface-chatbot")?document.getElementById("interface-chatbot").appendChild(e):document.body.appendChild(e)}n=!0,l({...a})}},document.addEventListener("DOMContentLoaded",loadContent),document?.body&&loadContent();const p=document.getElementById("iframe-component");p&&(p.onload=function(){console.log("ifram onload and remove event listener",t,"tempDataToSend"),p.contentWindow?.postMessage({type:o,data:t},"*")});let u="",g="Via socket",y="open",h="popup";InitializeInterface=function(){iframeController()},SendDataToInterface=function(e){e.theme&&l({theme:e.theme||"dark"}),!0===e.fullScreen||"true"===e.fullScreen?l({fullScreen:e.fullScreen}):!1!==e.fullScreen&&"false"!==e.fullScreen||l({fullScreen:e.fullScreen}),e&&p&&(t=e,p.contentWindow?.postMessage({type:o,data:e},"*"))},loadInterfaceEmbed=async function(){const t=document.getElementById("interface-main-script")?.getAttribute("embedToken");let n=`${e}?`,o={};if(t)o={method:"POST",headers:{"Content-Type":"application/json",Authorization:t}};else{const e=document.getElementById("interface-main-script")?.getAttribute("interface_id");e&&(o={method:"POST",body:JSON.stringify({isAnonymousUser:!0,interface_id:e}),headers:{"Content-Type":"application/json"}})}fetch("https://flow-api.viasocket.com/interfaces/loginuser",o).then((async e=>await e.json())).then((t=>{if(!document.getElementById("iframe-parent-container"))return;u=t?.data?.config,n=n.concat(`interfaceDetails=${JSON.stringify(t.data)}`);const o=document.getElementById("iframe-component")?.src?.split("?"),a=o?.[0];a!==e&&document.getElementById("iframe-component")&&(document.getElementById("iframe-component").src=n),u&&(u.title&&(g=u.title),u.buttonName&&(y=u.buttonName,document.getElementById("interfaceEmbed").innerText=y),u.type&&(document.getElementById("iframe-parent-container")?.classList.remove(`${h}-parent-container`),document.getElementById("interfaceEmbed")?.classList.remove(`${h}-interfaceEmbed`),h=u.type)),document.getElementById("iframe-parent-container")?.classList.add(`${h}-parent-container`),document.getElementById("interfaceEmbed")?.classList.add(`${h}-interfaceEmbed`),"all_space"===h?(document.getElementById("iframe-parent-container").style.height="100%",document.getElementById("iframe-parent-container").style.width="100%"):(document.getElementById("iframe-parent-container").style.height=`${u?.height}${u?.heightUnit||""}`||"70vh",document.getElementById("iframe-parent-container").style.width=`${u?.width}${u?.widthUnit||""}`||"40vw")})).catch((e=>{console.log("Fetch error:",e)}))},iframeController=function(){window.parent?.postMessage({type:"open",data:{}},"*"),document.getElementById("interfaceEmbed")&&document.getElementById("iframe-parent-container")&&(document.getElementById("interfaceEmbed").style.display="none",document.getElementById("iframe-parent-container").style.display="block",document.body.style.overflow="hidden")},loadInterfaceEmbed(),document.getElementById("interfaceEmbed")?.addEventListener("click",(()=>{window.InitializeInterface()}))})();