import { clearTimer } from "./ctaHelpers";
export const modalHelpers = {
    openModal(element, settings, callbacks) {
        if (settings === null || settings === void 0 ? void 0 : settings.clearMemory) {
            callbacks.clearSearchHistory();
        }
        requestAnimationFrame(() => {
            var _a, _b;
            const searchInput = element.shadowRoot.querySelector("ai12z-input-form").querySelector("textarea");
            searchInput.focus();
            element.shadowRoot.querySelector(".modal-wrapper").classList.add("show-modal");
            if (document.querySelector("ai12z-bot")) {
                const botEle = document.querySelector("ai12z-bot");
                (_a = botEle.shadowRoot.querySelector(".floating-icon")) === null || _a === void 0 ? void 0 : _a.classList.add("hide-chatbot");
                (_b = botEle.shadowRoot.querySelector("bot-popover")) === null || _b === void 0 ? void 0 : _b.classList.add("hide-chatbot");
            }
        });
        callbacks.onOpen();
        callbacks.setLocalData();
    },
    closeModal(element, timer, callbacks) {
        var _a, _b;
        element.shadowRoot.querySelector(".modal-wrapper").classList.remove("show-modal");
        if (document.querySelector("ai12z-bot")) {
            const botEle = document.querySelector("ai12z-bot");
            (_a = botEle.shadowRoot.querySelector(".floating-icon")) === null || _a === void 0 ? void 0 : _a.classList.remove("hide-chatbot");
            (_b = botEle.shadowRoot.querySelector("bot-popover")) === null || _b === void 0 ? void 0 : _b.classList.remove("hide-chatbot");
        }
        setTimeout(() => {
            callbacks.onClose();
            callbacks.onStopStream();
            clearTimer(timer);
        }, 300);
    },
    handleOutsideClick(ev, allowClose, closeModal) {
        const outsideContent = ev.target.classList.contains("modal-wrapper");
        if (outsideContent && allowClose && closeModal) {
            closeModal();
        }
    },
};
