import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';

const ToastRegion = /*@__PURE__*/ proxyCustomElement(class ToastRegion extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        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 h("slot", { key: '8ba16a1a1aa173043f4a14af432e11a82fffda5a' });
    }
    get el() { return this; }
    static get watchers() { return {
        "openToast": ["watchOpenToastHandler"]
    }; }
}, [4, "ic-toast-region", {
        "openToast": [1040]
    }, [[2, "icDismiss", "handleDismissedToast"]], {
        "openToast": ["watchOpenToastHandler"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["ic-toast-region"];
    components.forEach(tagName => { switch (tagName) {
        case "ic-toast-region":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, ToastRegion);
            }
            break;
    } });
}

const IcToastRegion = ToastRegion;
const defineCustomElement = defineCustomElement$1;

export { IcToastRegion, defineCustomElement };

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