import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
import { h as getOverlayContainer, c as cls } from './helpers.js';
import { T as Theme, Q as Query } from './theme.js';

const styleCss = ".modals-root-container{z-index:9000}x-modal{position:fixed;top:0px;left:0px;right:0px;bottom:0px;width:100%;max-width:100vw;height:100%;max-height:100vh;margin:0px;padding:0px;-webkit-transition:0.2s opacity;transition:0.2s opacity;background-color:rgba(255, 255, 255, 0.5);backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);opacity:0;visibility:hidden;z-index:9000;overflow:hidden;overflow-y:auto;display:block;pointer-events:none}.is-dark-mode x-modal{background-color:rgba(var(--color-dark-rgb, 31, 31, 31), 0.5)}x-modal.modal-closable{cursor:pointer}x-modal.modal-show{pointer-events:all;visibility:visible;opacity:1}x-modal.modal-show .modal-container>div{width:100% !important;opacity:1;-webkit-transform:translateY(0px);transform:translateY(0px)}x-modal .modal-interval-indicator{display:block;width:100%;background-color:rgba(var(--color-border-rgb, 200, 199, 204), 0.2);height:0.5rem;position:fixed;top:0px;z-index:10002;overflow:hidden}.is-dark-mode x-modal .modal-interval-indicator{background-color:rgba(255, 255, 255, 0.2)}x-modal .modal-interval-indicator>span{-webkit-animation-name:interval;animation-name:interval;-webkit-animation-timing-function:linear;animation-timing-function:linear;display:block;width:100%;height:0.5rem;background-color:rgba(var(--color-border-rgb, 200, 199, 204), 0.3)}.is-dark-mode x-modal .modal-interval-indicator>span{background-color:rgba(255, 255, 255, 0.3)}x-modal .modal-container{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;padding:1rem;min-height:100vh;max-width:100vw;z-index:9000}x-modal .modal-container>div{position:relative;min-width:18rem;width:100%;height:auto;cursor:default;margin:0;padding:0;opacity:0;-webkit-transition-delay:0.2s;transition-delay:0.2s;-webkit-transition:0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);transition:0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);-webkit-transform:translateY(100px);transform:translateY(100px)}x-modal .modal-container>div.modal-small{max-width:18rem}x-modal .modal-container>div.modal-regular{max-width:24rem}x-modal .modal-container>div.modal-normal{max-width:28rem}x-modal .modal-container>div.modal-medium{max-width:38rem}x-modal .modal-container>div.modal-big{max-width:48rem}x-modal .modal-container>div.modal-large{max-width:58rem}x-modal .modal-container>div.modal-full{max-width:calc(100% - 1rem)}x-modal .modal-container>div .modal-loading{width:18rem;height:0.5rem;border-radius:0.5rem;background-color:rgba(0, 0, 0, 0.1);-webkit-box-shadow:0px 0px 0px 2px rgba(0, 0, 0, 0.1);box-shadow:0px 0px 0px 2px rgba(0, 0, 0, 0.1);overflow:hidden;position:relative;margin:1rem auto}.is-dark-mode x-modal .modal-container>div .modal-loading{background-color:rgba(255, 255, 255, 0.2);-webkit-box-shadow:0px 0px 0px 3px rgba(255, 255, 255, 0.1);box-shadow:0px 0px 0px 3px rgba(255, 255, 255, 0.1)}x-modal .modal-container>div .modal-loading>span{display:block;position:absolute;content:\"\";left:-200px;width:200px;height:0.5rem;background-color:rgba(0, 0, 0, 0.5);animation:loading 1s linear infinite;-moz-animation:loading 1s linear infinite;-webkit-animation:loading 1s linear infinite;border-radius:0.5rem;background-color:var(--color-primary-tint, #5e8af4)}x-modal .modal-container>div .modal-body{background-color:var(--color-white, #FFFFFF);-webkit-box-shadow:0px 3px 1rem rgba(var(--color-border-rgb, 200, 199, 204), 0.2), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35);box-shadow:0px 3px 1rem rgba(var(--color-border-rgb, 200, 199, 204), 0.2), inset 0 0 0 1px rgba(var(--color-border-rgb, 200, 199, 204), 0.35);border:none;margin:0;border-radius:0.5rem;width:100%}.is-dark-mode x-modal .modal-container>div .modal-body{background-color:var(--color-black, #000000);-webkit-box-shadow:0px 3px 1rem rgba(var(--color-black-rgb, 0, 0, 0), 0.35), inset 0 0 0 1px var(--color-dark-tint, #414141);box-shadow:0px 3px 1rem rgba(var(--color-black-rgb, 0, 0, 0), 0.35), inset 0 0 0 1px var(--color-dark-tint, #414141)}";
const XModalStyle0 = styleCss;

const XModal$1 = /*@__PURE__*/ proxyCustomElement(class XModal extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.onOpen = createEvent(this, "open", 7);
        this.onClose = createEvent(this, "close", 7);
        this.loading = false;
        this.interval = undefined;
        this.size = 'normal';
        this.closable = true;
        this.visible = false;
    }
    onVisisbleValueChange(newValue) {
        (newValue ? this.onOpen : this.onClose).emit(this.el);
    }
    /**
     * Open the modal window
     */
    async open() {
        this.visible = true;
        if (this.interval && this.interval > 0) {
            this.timer = setTimeout(() => {
                this.close();
            }, this.interval * 1000);
        }
    }
    /**
     * Close the modal window
     */
    async close() {
        if (this.timer) {
            clearTimeout(this.timer);
        }
        this.visible = false;
        Theme.validateModals();
    }
    /**
     * On component did loaded hook
     */
    componentDidLoad() {
        const container = getOverlayContainer();
        const ref = this.el.getAttribute('ref');
        if (ref && Query(ref, container)) {
            Query(ref, container).remove();
        }
        container.appendChild(this.el);
    }
    /**
     * On click modal container handler
     *
     * @param e
     * @returns
     */
    onClickContainer(e) {
        if (this.loading || !this.closable) {
            return;
        }
        if ((e.target.classList.contains('modal') || e.target.classList.contains('modal-container'))) {
            this.close();
        }
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: 'af7b9481f5fba85f08d649bf93da3a169842b2c8', role: "modal", class: cls('modal', { 'modal-show': this.visible, 'modal-closable': this.closable }), onClick: this.onClickContainer.bind(this) }, h("div", { key: '9695f38db0c0c70b49300f3be1f6541c968e7b4f', class: "modal-container" }, this.loading ? h("div", null, h("div", { class: "d-none" }, h("slot", null)), h("div", { class: "modal-loading" }, h("span", null))) :
            h("div", { class: cls(`modal-${this.size}`) }, h("slot", null))), this.interval > 0 && this.visible && h("span", { key: '6c22bbdea8a15aaacc7157c1b41b91e7b2bcba43', class: "modal-interval-indicator" }, h("span", { key: '73a2fb71addf09eb436516c1858c78f15feed5b8', style: { animationDuration: this.interval + 's' } })));
    }
    ;
    get el() { return this; }
    static get watchers() { return {
        "visible": ["onVisisbleValueChange"]
    }; }
    static get style() { return XModalStyle0; }
}, [4, "x-modal", {
        "loading": [4],
        "interval": [2],
        "size": [1],
        "closable": [4],
        "visible": [32],
        "open": [64],
        "close": [64]
    }, undefined, {
        "visible": ["onVisisbleValueChange"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-modal"];
    components.forEach(tagName => { switch (tagName) {
        case "x-modal":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XModal$1);
            }
            break;
    } });
}

const XModal = XModal$1;
const defineCustomElement = defineCustomElement$1;

export { XModal, defineCustomElement };
