import{t,p as i,H as e,h as n}from"./p-ZGVz1_9H.js";import{L as o,a as d}from"./p-DPq7OOGr.js";const a=new o("LiveAgentChat",{logLevel:d.Info,remoteLoggingUrl:""}),s=i(class extends e{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.isApiReady=!1,this.chatButton=null,this.buttonId="ucu6zapn"}componentWillLoad(){var t;(null===(t=this.config)||void 0===t?void 0:t.buttonId)&&this.config.scriptSrc?this.loadLiveAgentScript():a.error("LiveAgentChat: `buttonId` and `scriptSrc` properties are required.")}loadLiveAgentScript(){var t;if(document.getElementById("la_x2s6df8d"))return void this.initializeApi();const i=document.createElement("script");i.id="la_x2s6df8d",i.async=!0,i.src=null===(t=this.config)||void 0===t?void 0:t.scriptSrc,i.onload=()=>{window.LiveAgent&&(this.chatButton=window.LiveAgent.createVirtualButton(this.buttonId,i),this.initializeApi())},document.body.appendChild(i)}initializeApi(){(null===window||void 0===window?void 0:window.LiveAgent)?this.isApiReady=!0:a.error("LiveAgentChat: LiveAgent API is not available or `whenReady` is not a function.")}async startChat(t){var i,e,n,o;return this.isApiReady?(null===(i=this.chatButton)||void 0===i||i.onClick(),null===(n=null===(e=window.LiveAgent)||void 0===e?void 0:e.startChat)||void 0===n||n.call(e,t||(null===(o=this.config)||void 0===o?void 0:o.buttonId)),window.addEventListener("message",(t=>{var i,e;if(t.origin.includes("ladesk.com")){if(null===(i=null==t?void 0:t.data)||void 0===i?void 0:i.includes("onEmbeddedChatOpened"))try{document.querySelector("ai12z-bot").action("minimize")}catch(t){a.error("Error fetching data:",t)}if(null===(e=null==t?void 0:t.data)||void 0===e?void 0:e.includes("closeOpenedWidget"))try{document.querySelector("ai12z-bot").action("open",{expanded:!1})}catch(t){a.error("Error fetching data:",t)}}})),Promise.resolve()):(a.error("LiveAgentChat: API is not ready. Cannot start chat."),Promise.reject("API not ready"))}render(){return n("slot",{key:"a0d32db2683a293d3b4b232fc65cd63461670af1"})}},[257,"live-agent-chat",{config:[8],isApiReady:[32],startChat:[64]}]);function r(){"undefined"!=typeof customElements&&["live-agent-chat"].forEach((i=>{"live-agent-chat"===i&&(customElements.get(t(i))||customElements.define(t(i),s))}))}r();export{s as L,r as d}