'use strict';

var index = require('./index-Ct2DwlDF.js');
var utils = require('./utils-BAJarpnb.js');
var analyticsService = require('./analyticsService-CkAva47S.js');
var logger$1 = require('./logger-B_JTV5L8.js');

const ChatAvatar = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
    }
    render() {
        if (!this.senderType)
            return null;
        return (
        // <div class="avatar-column flex items-start"> {`text-${this.senderType === "agent" ? "blue" : ""}`}
        index.h("div", { class: `rounded-full w-6 h-6 p-2 grid place-content-center` }, this.avatarUrl ? (index.h("img", { src: this.avatarUrl, class: "w-8 h-8 rounded-full", alt: `${this.senderType} avatar` })) : (index.h("i", { class: `block text-body1 default-botAvatar`, title: `${this.senderType} avatar`, "aria-label": `${this.senderType} avatar` }, this.senderType === "bot" ? (index.h("svg", { width: "28", height: "28", viewBox: "0 0 48 48", fill: "currentColor", xmlns: "http://www.w3.org/2000/svg" }, index.h("path", { d: "M24 2c-3 8-8 13-16 16 8 3 13 8 16 16 3-8 8-13 16-16-8-3-13-8-16-16z" }))) : (index.h("svg", { class: "w-5 h-5", viewBox: "0 0 24 24", fill: "currentColor", height: "20", width: "20", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, index.h("path", { d: "M12 12c2.76 0 5-2.24 5-5s-2.24-5-5-5S7 4.24 7 7s2.24 5 5 5zm0 2c-3.31 0-6 2.69-6 6v1h12v-1c0-3.31-2.69-6-6-6z" }))))))
        // </div>
        );
    }
};

const HamburgerMenu = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.hamburgerMenuClick = index.createEvent(this, "hamburgerMenuClick", 7);
        this.handleByLiveAgent = index.createEvent(this, "handleByLiveAgent", 7);
        this.toggledChange = index.createEvent(this, "toggledChange", 7);
        this.isToggled = false;
        this.messages = [];
        this.isLiveAgentEnabled = false;
        this.hasCheckedLiveAgent = false; // ✅ Track if we've already checked
        this.liveAgentButtonText = "Connect to Live Agent";
        // ✅ bind once so add/remove work
        this.boundHandleClickOutside = this.handleClickOutside.bind(this);
    }
    handleClickOutside(event) {
        // Check if the clicked target is outside the menu
        const target = event.target;
        if (this.isToggled && this.menuV2Ref && !this.menuV2Ref.contains(target)) {
            // console.log("Clicked outside the menu, closing...")
            this.isToggled = false;
            this.toggledChange.emit(this.isToggled);
        }
        // if (this.showMenu && this.plusIconRef && !this.plusIconRef.contains(target)) {
        //   this.showMenu = false
        // }
    }
    /** ✅ Watch for isToggled changes to attach/remove listener dynamically */
    watchToggled(newValue) {
        if (newValue === true) {
            document.addEventListener("click", this.boundHandleClickOutside);
        }
        else {
            document.removeEventListener("click", this.boundHandleClickOutside);
        }
    }
    // ✅ Watch messages array but only check once
    watchMessages(newMessages) {
        // Only check if we haven't checked before AND we have enough messages
        if (!this.hasCheckedLiveAgent && newMessages && newMessages.length === 2) {
            this.hasCheckedLiveAgent = true; // ✅ Mark as checked so it won't run again
        }
    }
    watchLiveAgentButtonText(newText) {
        if (!newText || newText.trim() === "") {
            this.liveAgentButtonText = "Connect to Live Agent";
        }
    }
    componentDidLoad() {
        if (this.isToggled) {
            document.addEventListener("click", this.boundHandleClickOutside);
        }
    }
    disconnectedCallback() {
        document.removeEventListener("click", this.boundHandleClickOutside);
    }
    render() {
        var _a, _b;
        return (index.h("div", { key: 'fb76552fc3799bef70ebddc3833e99b9058f180d', id: "dropdown-menu", role: "menu", class: `flex flex-col gap-y-1 grow-wrap absolute bg-white border-b border-gray-80 border-solid rounded-lg shadow-lg p-2 mt-4 min-w-[200px] left-5 overflow-hidden ${this.isToggled ? "show" : ""} dropdown-menu`, style: { height: "auto" }, ref: el => (this.menuV2Ref = el) }, (_b = (_a = this.botSettings) === null || _a === void 0 ? void 0 : _a.buttons) === null || _b === void 0 ? void 0 :
            _b.map(button => (index.h("div", { class: "w-full dropdown-item" }, index.h("button", { class: "dropdown-item-button", role: "menuitem", "aria-label": button.label, onClick: _e => {
                    this.hamburgerMenuClick.emit({ button, type: 'menu' });
                } }, button.label)))), index.h("div", { key: 'e9df71a3d62ac65517854d31816d08bdaff947e6', class: "w-full dropdown-item" }, index.h("button", { key: 'f043a9273787790c12e1a8a002982f16a21925b0', class: "dropdown-item-button", role: "menuitem", "aria-label": "Start Over", "aria-disabled": this.messages.length === 0, disabled: this.messages.length === 0, style: { opacity: this.messages.length === 0 ? "0.5" : "1", cursor: this.messages.length === 0 ? "not-allowed" : "pointer" }, onClick: ev => {
                ev.preventDefault();
                this.hamburgerMenuClick.emit({ type: 'startover', event: ev });
            } }, "Start Over")), index.h("div", { key: 'f434964275c80de42847907f60711eaef0ce0460', class: "w-full dropdown-item" }, index.h("button", { key: 'ed23384ef53f9e9b25a8215bafcfda0f51778f6c', class: "dropdown-item-button", role: "menuitem", "aria-label": "View Recent Chat", onClick: _e => {
                this.hamburgerMenuClick.emit({ type: 'history' });
            } }, "View Recent chat")), this.isLiveAgentEnabled && this.botSettings.enableHamburgerMenu && (index.h("div", { key: 'd0fdceeb92d6ec7b1754c5e338dddeaf6ca46081', class: "w-full dropdown-item" }, index.h("button", { key: '21d6f48f44898a459b0224cdab3f65ed0b93124c', class: `dropdown-item-button ${!this.isLiveAgentEnabled ? "opacity-50 cursor-not-allowed pointer-events-none" : "opacity-100 cursor-pointer"}`, role: "menuitem", "aria-label": this.liveAgentButtonText, style: { opacity: !this.isLiveAgentEnabled ? "0.5" : "1", cursor: !this.isLiveAgentEnabled ? "not-allowed" : "pointer" }, onClick: ev => {
                ev.preventDefault();
                if (!this.isLiveAgentEnabled)
                    return;
                this.handleByLiveAgent.emit();
            } }, this.liveAgentButtonText)))));
    }
    static get watchers() { return {
        "isToggled": [{
                "watchToggled": 0
            }],
        "messages": [{
                "watchMessages": 0
            }],
        "liveAgentButtonText": [{
                "watchLiveAgentButtonText": 0
            }]
    }; }
};

function disableFeedback(id, element) {
    const thumbsUp = element.querySelector(`#thumbsUp_${id}`);
    const thumbsDown = element.querySelector(`#thumbsDown_${id}`);
    thumbsUp.classList.add("not-allowed");
    thumbsUp.setAttribute("disabled", "true");
    thumbsDown.classList.add("not-allowed");
    thumbsDown.setAttribute("disabled", "true");
}
function thumbsUp(id, insightId, element, payload) {
    const thumbsUp = element.querySelector(`#thumbsUp_${id}`);
    thumbsUp.classList.add("thumbs-up");
    thumbsUp.innerHTML = `
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"  fill="currentColor">
        <path  d="M7.493 18.5c-.425 0-.82-.236-.975-.632A7.48 7.48 0 0 1 6 15.125c0-1.75.599-3.358 1.602-4.634.151-.192.373-.309.6-.397.473-.183.89-.514 1.212-.924a9.042 9.042 0 0 1 2.861-2.4c.723-.384 1.35-.956 1.653-1.715a4.498 4.498 0 0 0 .322-1.672V2.75A.75.75 0 0 1 15 2a2.25 2.25 0 0 1 2.25 2.25c0 1.152-.26 2.243-.723 3.218-.266.558.107 1.282.725 1.282h3.126c1.026 0 1.945.694 2.054 1.715.045.422.068.85.068 1.285a11.95 11.95 0 0 1-2.649 7.521c-.388.482-.987.729-1.605.729H14.23c-.483 0-.964-.078-1.423-.23l-3.114-1.04a4.501 4.501 0 0 0-1.423-.23h-.777ZM2.331 10.727a11.969 11.969 0 0 0-.831 4.398 12 12 0 0 0 .52 3.507C2.28 19.482 3.105 20 3.994 20H4.9c.445 0 .72-.498.523-.898a8.963 8.963 0 0 1-.924-3.977c0-1.708.476-3.305 1.302-4.666.245-.403-.028-.959-.5-.959H4.25c-.832 0-1.612.453-1.918 1.227Z" />
        </svg>
    `;
    disableFeedback(id, element);
    utils.sendFeedback(payload.dataKey, payload.dataMode, insightId, { value: 1 });
    // this.feedback.emit({ insightId: insightId, feedback: { value: 1 } })
    // Track analytics event
    analyticsService.trackFeedbackAnalytics("up", insightId || id, payload);
}
function thumbsDown(id, insightId, element, payload) {
    const thumbsDown = element.querySelector(`#thumbsDown_${id}`);
    thumbsDown.classList.add("thumbs-down");
    thumbsDown.innerHTML = `
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
        <path d="M15.73 5.5h1.035A7.465 7.465 0 0 1 18 9.625a7.465 7.465 0 0 1-1.235 4.125h-.148c-.806 0-1.534.446-2.031 1.08a9.04 9.04 0 0 1-2.861 2.4c-.723.384-1.35.956-1.653 1.715a4.499 4.499 0 0 0-.322 1.672v.633A.75.75 0 0 1 9 22a2.25 2.25 0 0 1-2.25-2.25c0-1.152.26-2.243.723-3.218.266-.558-.107-1.282-.725-1.282H3.622c-1.026 0-1.945-.694-2.054-1.715A12.137 12.137 0 0 1 1.5 12.25c0-2.848.992-5.464 2.649-7.521C4.537 4.247 5.136 4 5.754 4H9.77a4.5 4.5 0 0 1 1.423.23l3.114 1.04a4.5 4.5 0 0 0 1.423.23ZM21.669 14.023c.536-1.362.831-2.845.831-4.398 0-1.22-.182-2.398-.52-3.507-.26-.85-1.084-1.368-1.973-1.368H19.1c-.445 0-.72.498-.523.898.591 1.2.924 2.55.924 3.977a8.958 8.958 0 0 1-1.302 4.666c-.245.403.028.959.5.959h1.053c.832 0 1.612-.453 1.918-1.227Z" />
        </svg>
    `;
    disableFeedback(id, element);
    utils.sendFeedback(payload.dataKey, payload.dataMode, insightId, { value: -1 });
    // this.feedback.emit({ insightId: insightId, feedback: { value: -1 } })
    // Track analytics event
    analyticsService.trackFeedbackAnalytics("down", insightId || id, payload);
}

const interactionButtonsCss = () => ``;

const InteractionButtons = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.voiceType = "default"; // default or google
        this.voice = "Google US English";
        this.source = "";
        this.conversationId = "";
        this.projectId = "";
        this.isPlayed = false;
        this.audioElement = null;
        this.copied = false;
    }
    // Function to copy the text to clipboard
    copyToClipboard(text) {
        navigator.clipboard
            .write([
            new ClipboardItem({
                "text/html": new Blob([text], { type: "text/html" }),
                "text/plain": new Blob([utils.removeHtmlTags(text)], { type: "text/plain" }),
            }),
        ])
            .then(() => {
            // console.log("Text copied to clipboard", text)
            this.copied = true; // Set a flag to show copied state
            setTimeout(() => {
                this.copied = false; // Reset copied state after 2 seconds
            }, 2000);
        });
    }
    // Function to trigger the text-to-speech
    async speakText(msg) {
        if (this.voiceType === "default") {
            if ("speechSynthesis" in window) {
                const voices = window.speechSynthesis.getVoices();
                const voice = voices.find(voice => voice.name === this.voice);
                this.isPlayed = true;
                const utterance = new SpeechSynthesisUtterance(msg); // Create a speech synthesis utterance
                utterance.lang = "en-US"; // Set the language, you can change this as needed
                utterance.rate = 1;
                utterance.pitch = 1;
                utterance.voice = voice;
                // Speak the text
                window.speechSynthesis.speak(utterance);
            }
            else {
                alert("Speech Synthesis API is not supported in your browser.");
            }
        }
        if (this.voiceType === "google") {
            const base64audiocontent = await utils.getAudioContent(this.dataKey, this.dataMode, msg, this.voice);
            const audioBlob = utils.base64ToBlob(base64audiocontent.audio_content, "audio/mpeg");
            const audioUrl = URL.createObjectURL(audioBlob);
            // Create the audio element
            this.audioElement = new Audio(audioUrl);
            this.audioElement.onended = () => {
                // this.isPlaying = false
                this.isPlayed = false;
            };
            if (this.audioElement.paused) {
                this.audioElement.play();
                this.isPlayed = true;
            }
            else {
                this.audioElement.pause();
                this.audioElement.currentTime = 0;
                this.audioElement.src = ""; // Remove the audio source
                this.audioElement = null; // Dereference the object
                this.isPlayed = false;
            }
        }
    }
    render() {
        var _a;
        const email = "";
        return (index.h("div", { key: '1301676693d2dae8759c238c2528b54d2179454e', class: "thumbs-container flex gap-2 mt-2" }, this.isPlayed && (index.h("button", { key: '10cd8e47e1c37f28f1238c1b7288db94b9ce8f3c', class: "copy-btn", tabindex: "0", "aria-label": "Stop Speaking", onClick: () => {
                this.isPlayed = false;
                window.speechSynthesis.cancel();
                if (this.audioElement) {
                    this.audioElement.pause();
                    this.audioElement.currentTime = 0;
                    this.audioElement.src = ""; // Remove the audio source
                    this.audioElement = null; // Dereference the object
                }
                // this.isPlayed = false
            } }, index.h("svg", { key: '7917d77a2ae82e41ecca58761b24bdd40ed901f8', width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", class: "icon-md-heavy" }, index.h("path", { key: '709788d90a11ef6e33c4b504b58f5daab0d91d6d', "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22C6.47715 22 2 17.5228 2 12ZM9.5 8.5C8.94772 8.5 8.5 8.94772 8.5 9.5V14.5C8.5 15.0523 8.94772 15.5 9.5 15.5H14.5C15.0523 15.5 15.5 15.0523 15.5 14.5V9.5C15.5 8.94772 15.0523 8.5 14.5 8.5H9.5Z", fill: "currentColor" })))), !this.isPlayed && (index.h("button", { key: '007f1ba6c2f17d809dafb460e49e6d58cac83b2f', class: "copy-btn", tabindex: "0", onClick: () => this.speakText(utils.removeHtmlTags(this.message.text)), "aria-label": "Speak Text" }, index.h("svg", { key: 'ff62913d5c73c19b3b1bdf5b37057cc9e022fda4', class: "w-6 h-6", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, index.h("path", { key: '8186495b322cd06040e9ea23e50d2c9ea50bebd4', "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M11 4.9099C11 4.47485 10.4828 4.24734 10.1621 4.54132L6.67572 7.7372C6.49129 7.90626 6.25019 8.00005 6 8.00005H4C3.44772 8.00005 3 8.44776 3 9.00005V15C3 15.5523 3.44772 16 4 16H6C6.25019 16 6.49129 16.0938 6.67572 16.2629L10.1621 19.4588C10.4828 19.7527 11 19.5252 11 19.0902V4.9099ZM8.81069 3.06701C10.4142 1.59714 13 2.73463 13 4.9099V19.0902C13 21.2655 10.4142 22.403 8.81069 20.9331L5.61102 18H4C2.34315 18 1 16.6569 1 15V9.00005C1 7.34319 2.34315 6.00005 4 6.00005H5.61102L8.81069 3.06701ZM20.3166 6.35665C20.8019 6.09313 21.409 6.27296 21.6725 6.75833C22.5191 8.3176 22.9996 10.1042 22.9996 12.0001C22.9996 13.8507 22.5418 15.5974 21.7323 17.1302C21.4744 17.6185 20.8695 17.8054 20.3811 17.5475C19.8927 17.2896 19.7059 16.6846 19.9638 16.1962C20.6249 14.9444 20.9996 13.5175 20.9996 12.0001C20.9996 10.4458 20.6064 8.98627 19.9149 7.71262C19.6514 7.22726 19.8312 6.62017 20.3166 6.35665ZM15.7994 7.90049C16.241 7.5688 16.8679 7.65789 17.1995 8.09947C18.0156 9.18593 18.4996 10.5379 18.4996 12.0001C18.4996 13.3127 18.1094 14.5372 17.4385 15.5604C17.1357 16.0222 16.5158 16.1511 16.0539 15.8483C15.5921 15.5455 15.4632 14.9255 15.766 14.4637C16.2298 13.7564 16.4996 12.9113 16.4996 12.0001C16.4996 10.9859 16.1653 10.0526 15.6004 9.30063C15.2687 8.85905 15.3578 8.23218 15.7994 7.90049Z", fill: "currentColor" })))), index.h("button", { key: '73b95dd34970f896e9ad3a5641924b5cb825a6ec', id: `thumbsUp_${this.message.thumbsId}`, tabindex: "0", onClick: () => {
                var _a;
                thumbsUp(this.message.thumbsId, this.message.insightId, this.el, {
                    dataKey: this.dataKey,
                    dataMode: this.dataMode,
                    conversationId: this.conversationId,
                    projectId: this.projectId,
                    questionText: ((_a = this.chatArray[this.currentIndex - 1]) === null || _a === void 0 ? void 0 : _a.text) || "",
                });
            }, class: "chat-thumbs-up", "aria-label": "Thumbs Up" }, index.h("svg", { key: 'ac3bd7b9dca8a7b2fe280f454bfa719aa5064bb5', xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", "stroke-width": "1.5", stroke: "currentColor", class: "w-6 h-6" }, index.h("path", { key: '24d32fb905fd8499f529f7ab8fdbb28f4428f192', "stroke-linecap": "round", "stroke-linejoin": "round", d: "M6.633 10.25c.806 0 1.533-.446 2.031-1.08a9.041 9.041 0 0 1 2.861-2.4c.723-.384 1.35-.956 1.653-1.715a4.498 4.498 0 0 0 .322-1.672V2.75a.75.75 0 0 1 .75-.75 2.25 2.25 0 0 1 2.25 2.25c0 1.152-.26 2.243-.723 3.218-.266.558.107 1.282.725 1.282m0 0h3.126c1.026 0 1.945.694 2.054 1.715.045.422.068.85.068 1.285a11.95 11.95 0 0 1-2.649 7.521c-.388.482-.987.729-1.605.729H13.48c-.483 0-.964-.078-1.423-.23l-3.114-1.04a4.501 4.501 0 0 0-1.423-.23H5.904m10.598-9.75H14.25M5.904 18.5c.083.205.173.405.27.602.197.4-.078.898-.523.898h-.908c-.889 0-1.713-.518-1.972-1.368a12 12 0 0 1-.521-3.507c0-1.553.295-3.036.831-4.398C3.387 9.953 4.167 9.5 5 9.5h1.053c.472 0 .745.556.5.96a8.958 8.958 0 0 0-1.302 4.665c0 1.194.232 2.333.654 3.375Z" }))), index.h("button", { key: 'e88dacbba6d2b8d45beb06a7d5b6e60405fa11d4', id: `thumbsDown_${this.message.thumbsId}`, onClick: () => {
                var _a;
                return thumbsDown(this.message.thumbsId, this.message.insightId, this.el, {
                    dataKey: this.dataKey,
                    dataMode: this.dataMode,
                    conversationId: this.conversationId,
                    projectId: this.projectId,
                    questionText: ((_a = this.chatArray[this.currentIndex - 1]) === null || _a === void 0 ? void 0 : _a.text) || "",
                });
            }, class: "chat-thumbs-up", "aria-label": "Thumbs Down" }, index.h("svg", { key: 'b23d5fa5643c1e6cc6f3026385a8d7cb93bc6693', xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", "stroke-width": "1.5", stroke: "currentColor", class: "w-6 h-6" }, index.h("path", { key: '20c32a05eb6e12926ac553a1ab4bed9e45fceb7e', "stroke-linecap": "round", "stroke-linejoin": "round", d: "M7.498 15.25H4.372c-1.026 0-1.945-.694-2.054-1.715a12.137 12.137 0 0 1-.068-1.285c0-2.848.992-5.464 2.649-7.521C5.287 4.247 5.886 4 6.504 4h4.016a4.5 4.5 0 0 1 1.423.23l3.114 1.04a4.5 4.5 0 0 0 1.423.23h1.294M7.498 15.25c.618 0 .991.724.725 1.282A7.471 7.471 0 0 0 7.5 19.75 2.25 2.25 0 0 0 9.75 22a.75.75 0 0 0 .75-.75v-.633c0-.573.11-1.14.322-1.672.304-.76.93-1.33 1.653-1.715a9.04 9.04 0 0 0 2.86-2.4c.498-.634 1.226-1.08 2.032-1.08h.384m-10.253 1.5H9.7m8.075-9.75c.01.05.027.1.05.148.593 1.2.925 2.55.925 3.977 0 1.487-.36 2.89-.999 4.125m.023-8.25c-.076-.365.183-.75.575-.75h.908c.889 0 1.713.518 1.972 1.368.339 1.11.521 2.287.521 3.507 0 1.553-.295 3.036-.831 4.398-.306.774-1.086 1.227-1.918 1.227h-1.053c-.472 0-.745-.556-.5-.96a8.95 8.95 0 0 0 .303-.54" }))), index.h("button", { key: '3c6b36fba4822583aa696ecb0554d7f21bb16ee7', class: "copy-btn", onClick: () => this.copyToClipboard(this.message.text), "aria-label": "Copy Text" }, !this.copied && (index.h("svg", { key: '8894cf516b01e42bb49103091ba8b7a79b1b28b9', class: "w-6 h-6", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, index.h("path", { key: '9f0571488b60f8b39794c78cb962a3e0c5d0273a', "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M7 5C7 3.34315 8.34315 2 10 2H19C20.6569 2 22 3.34315 22 5V14C22 15.6569 20.6569 17 19 17H17V19C17 20.6569 15.6569 22 14 22H5C3.34315 22 2 20.6569 2 19V10C2 8.34315 3.34315 7 5 7H7V5ZM9 7H14C15.6569 7 17 8.34315 17 10V15H19C19.5523 15 20 14.5523 20 14V5C20 4.44772 19.5523 4 19 4H10C9.44772 4 9 4.44772 9 5V7ZM5 9C4.44772 9 4 9.44772 4 10V19C4 19.5523 4.44772 20 5 20H14C14.5523 20 15 19.5523 15 19V10C15 9.44772 14.5523 9 14 9H5Z", fill: "currentColor" }))), this.copied && (index.h("svg", { key: '389e0dd0c42e6a2686a66a898b6b3727eb9f104b', viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", class: "w-6 h-6" }, index.h("path", { key: '00419fae11b47645d88eff7bc416ca20c0142d1d', "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M19.8198 6.19526C20.0601 6.45561 20.0601 6.87772 19.8198 7.13807L9.9736 17.8047C9.73328 18.0651 9.34364 18.0651 9.10332 17.8047L4.18024 12.4714C3.93992 12.2111 3.93992 11.7889 4.18024 11.5286C4.42056 11.2682 4.8102 11.2682 5.05053 11.5286L9.53846 16.3905L18.9495 6.19526C19.1898 5.93491 19.5794 5.93491 19.8198 6.19526Z", fill: "currentColor" })))), index.h("button", { key: 'bc7d7e38758231b7f146300a5f8876c6082666b3', class: "copy-btn", "aria-label": "Send Email" }, index.h("a", { key: '0d3f2e732bb670fa494b50cc2151f6770e221a57', href: `mailto:${email}?subject=${encodeURIComponent((_a = this.chatArray[this.currentIndex - 1]) === null || _a === void 0 ? void 0 : _a.text)}&body=${encodeURIComponent(utils.removeHtmlTags(this.message.text))}`, target: "_blank" }, index.h("svg", { key: '4cff30b349e567b0ddc05b7dfeef3cea54c2b1fa', viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", stroke: "currentColor", "stroke-width": "0.3", class: "w-6 h-6" }, index.h("path", { key: 'ba202044b745f9d37b91520cff1086941f155c56', "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M3.75 5.25L3 6V18L3.75 18.75H20.25L21 18V6L20.25 5.25H3.75ZM4.5 7.6955V17.25H19.5V7.69525L11.9999 14.5136L4.5 7.6955ZM18.3099 6.75H5.68986L11.9999 12.4864L18.3099 6.75Z", fill: "currentColor" }), " ")))));
    }
    get el() { return index.getElement(this); }
};
InteractionButtons.style = interactionButtonsCss();

const logger = new logger$1.Logger("LiveAgentChat", {
    logLevel: logger$1.LogLevel.Info, // Set to Debug for detailed logs",
    remoteLoggingUrl: "",
});
const LiveAgentChat = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        /**
         * Internal state to track if the LiveAgent API is ready.
         */
        this.isApiReady = false;
        this.chatButton = null;
        this.buttonId = "ucu6zapn";
    }
    /**
     * Stencil lifecycle hook that runs once when the component is first connected to the DOM.
     */
    componentWillLoad() {
        var _a;
        if (!((_a = this.config) === null || _a === void 0 ? void 0 : _a.buttonId) || !this.config.scriptSrc) {
            logger.error("LiveAgentChat: `buttonId` and `scriptSrc` properties are required.");
            return;
        }
        this.loadLiveAgentScript();
    }
    /**
     * Dynamically loads the LiveAgent track.js script into the document.
     */
    loadLiveAgentScript() {
        var _a;
        // Check if the script is already added to avoid duplicates
        if (document.getElementById("la_x2s6df8d")) {
            this.initializeApi();
            return;
        }
        const script = document.createElement("script");
        script.id = "la_x2s6df8d";
        script.async = true;
        script.src = (_a = this.config) === null || _a === void 0 ? void 0 : _a.scriptSrc;
        script.onload = () => {
            if (window.LiveAgent) {
                this.chatButton = window.LiveAgent.createVirtualButton(this.buttonId, script);
                this.initializeApi();
            }
        };
        document.body.appendChild(script);
    }
    /**
     * Initializes the event handlers for the LiveAgent API, waiting for it to be ready.
     */
    initializeApi() {
        if (window === null || window === void 0 ? void 0 : window.LiveAgent) {
            this.isApiReady = true;
        }
        else {
            logger.error("LiveAgentChat: LiveAgent API is not available or `whenReady` is not a function.");
        }
    }
    // 🔹 Public method to start the chat manually
    async startChat(_buttonId) {
        var _a, _b, _c, _d;
        if (!this.isApiReady) {
            logger.error("LiveAgentChat: API is not ready. Cannot start chat.");
            return Promise.reject("API not ready");
        }
        (_a = this.chatButton) === null || _a === void 0 ? void 0 : _a.onClick();
        (_c = (_b = window.LiveAgent) === null || _b === void 0 ? void 0 : _b.startChat) === null || _c === void 0 ? void 0 : _c.call(_b, _buttonId || ((_d = this.config) === null || _d === void 0 ? void 0 : _d.buttonId));
        window.addEventListener("message", event => {
            var _a, _b;
            if (event.origin.includes("ladesk.com")) {
                if ((_a = event === null || event === void 0 ? void 0 : event.data) === null || _a === void 0 ? void 0 : _a.includes("onEmbeddedChatOpened")) {
                    try {
                        const botElement = document.querySelector("ai12z-bot");
                        botElement.action("minimize");
                    }
                    catch (error) {
                        logger.error("Error fetching data:", error);
                    }
                }
                if ((_b = event === null || event === void 0 ? void 0 : event.data) === null || _b === void 0 ? void 0 : _b.includes("closeOpenedWidget")) {
                    try {
                        const botElement = document.querySelector("ai12z-bot");
                        botElement.action("open", { expanded: false });
                    }
                    catch (error) {
                        logger.error("Error fetching data:", error);
                    }
                }
            }
        });
        return Promise.resolve();
    }
    /**
     * This component does not render its own UI. It provides functionality
     * to its parent through events and methods. A <slot> can allow the parent
     * to project content if needed, but is not required.
     */
    render() {
        return index.h("slot", { key: 'a0d32db2683a293d3b4b232fc65cd63461670af1' });
    }
};

const privacyModalCss = () => `.link-privacy-modal{color:var(--ai12zBot-v2-privacy-link-color);font-size:var(--ai12zBot-v2-privacy-link-font-size)}.privacy-msg{font-size:var(--ai12zBot-v2-privacy-text-font-size);color:var(--ai12zBot-v2-privacy-text-color)}`;

const PrivacyModal = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
    }
    componentWillLoad() {
        utils.insertStyles(`https://cdn.ai12z.net/assets/bot/v2/tailwind.min.css`, this.el);
    }
    render() {
        if (!this.show)
            return null;
        return (index.h("div", { class: "w-full" }, index.h("div", { class: "privacy-msg", innerHTML: this.message })));
    }
    get el() { return index.getElement(this); }
};
PrivacyModal.style = privacyModalCss();

const typingIndicatorCss = () => `.typing-indicator{display:flex;align-items:center;justify-content:flex-start;height:24px}.dot{border-radius:50%;animation:typing-bounce 1.4s infinite ease-in-out both}@keyframes typing-bounce{0%,80%,100%{transform:scale(0);opacity:0.3}40%{transform:scale(1);opacity:1}}`;

const TypingIndicator = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        /** Size of dots in pixels (e.g., 8 = 8px) */
        this.size = 10;
        /** Color of dots (any valid CSS color) */
        this.color = "#4e7becc0"; // Tailwind blue-500
        /** Gap between dots in pixels */
        this.spacing = 6;
    }
    render() {
        const dotStyle = {
            width: `${this.size}px`,
            height: `${this.size}px`,
            backgroundColor: this.color,
            marginRight: `${this.spacing}px`,
        };
        return (index.h("div", { key: 'bd85182ca31ecc6d35c911a567daed098164ea59', class: "typing-indicator", role: "status", "aria-live": "polite", "aria-label": "Typing indicator" }, index.h("span", { key: '63c24fa73702c58e120f8be7f41829b9776c0fb4', class: "dot", style: Object.assign(Object.assign({}, dotStyle), { animationDelay: "0s" }) }), index.h("span", { key: '9dc45671673597a3e62d837a6bba1e91cf6597ef', class: "dot", style: Object.assign(Object.assign({}, dotStyle), { animationDelay: "0.2s" }) }), index.h("span", { key: '9c820b6f1255c932301c46c3d1abc51ff6d1dd87', class: "dot", style: Object.assign(Object.assign({}, dotStyle), { marginRight: "0", animationDelay: "0.4s" }) })));
    }
};
TypingIndicator.style = typingIndicatorCss();

exports.chat_avatar = ChatAvatar;
exports.hamburger_menu = HamburgerMenu;
exports.interaction_buttons = InteractionButtons;
exports.live_agent_chat = LiveAgentChat;
exports.privacy_modal = PrivacyModal;
exports.typing_indicator = TypingIndicator;
