'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-d337cd8a.js');

const ToastRegion = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.pendingVisibility = [];
        this.showToast = (toast) => {
            const visibleToasts = Array.from(document.querySelectorAll("ic-toast")).filter((el) => window.getComputedStyle(el).display !== "none");
            if (visibleToasts.indexOf(toast) === -1 && visibleToasts.length <= 0) {
                toast.setVisible().then((res) => (this.previouslyFocused = res));
            }
            if (visibleToasts.length > 0)
                this.pendingVisibility.push(toast);
        };
    }
    watchOpenToastHandler(newValue) {
        if (this.openToast !== undefined) {
            this.showToast(newValue);
            this.openToast = undefined;
        }
    }
    componentDidLoad() {
        if (this.openToast) {
            this.showToast(this.openToast);
            this.openToast = undefined;
        }
    }
    handleDismissedToast() {
        var _a;
        if (this.pendingVisibility.length > 0) {
            this.pendingVisibility[0]
                .setVisible()
                .then((res) => (this.previouslyFocused = res));
            this.pendingVisibility.shift();
        }
        else {
            if (this.previouslyFocused && "setFocus" in this.previouslyFocused) {
                this.previouslyFocused.setFocus();
            }
            else
                (_a = this.previouslyFocused) === null || _a === void 0 ? void 0 : _a.focus();
        }
    }
    render() {
        return index.h("slot", { key: '8ba16a1a1aa173043f4a14af432e11a82fffda5a' });
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "openToast": ["watchOpenToastHandler"]
    }; }
};

exports.ic_toast_region = ToastRegion;

//# sourceMappingURL=ic-toast-region.cjs.entry.js.map