import { r as registerInstance, c as createEvent, h, H as Host, g as getElement } from './index-6191c26c.js';
import { e as evaluateOverlayIndex, f as getOverlayContainer, c as cls } from './helpers-2fce0c0e.js';
import { T as Theme, Q as Query } from './theme-83657d68.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-loading .modal-slot{display:none}x-modal .modal-slot,x-modal .modal-loading{-webkit-animation:0.4s fadeIn;animation:0.4s fadeIn}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}.is-mobile x-modal .modal-container{-ms-flex-align:end;align-items:flex-end;padding:0.35rem;padding-bottom:calc(0.35rem + var(--inset-bottom))}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-duration:0.3s;transition-duration:0.3s;-webkit-transition-timing-function:cubic-bezier(0.175, 0.885, 0.32, 1.275);transition-timing-function: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:100%}.is-mobile x-modal .modal-container>div{max-width:100% !important}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;animation:loading 1s linear infinite;-moz-animation:loading 1s linear infinite;-webkit-animation:loading 1s linear infinite;border-radius:0.5rem;background-color:rgba(0, 0, 0, 0.5);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 = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.onOpen = createEvent(this, "open", 3);
        this.onClose = createEvent(this, "close", 3);
        this.loading = false;
        this.interval = undefined;
        this.size = 'normal';
        this.maxWidth = undefined;
        this.closable = true;
        this.visible = false;
    }
    /**
     * Observe the visible changes
     */
    watchVisible(newValue) {
        newValue && evaluateOverlayIndex(this.el);
        (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: '39f3bf2078528b53f6f3c447606050e2cf4444bb', role: "modal", class: cls('modal', { 'modal-show': this.visible, 'modal-closable': this.closable, 'modal-loading': this.loading }), onClick: this.onClickContainer.bind(this) }, h("div", { key: '52dc025064e30bc96f8de4797d4417eae3e304a6', class: "modal-container" }, this.loading && h("div", { key: 'c0276a0dfb58a5c5848881037ec9b1fd01ad0313' }, h("div", { key: '1ee10a8e4db01da0f8ec350520003a61016cdc1b', class: "modal-loading" }, h("span", { key: '728d3337dedcfcf61c276d8f32aaa5639de015a3' }))), h("div", { key: '084add3d0a6a5e59c97e83ff8593328e550d020d', class: cls('modal-slot', `modal-${this.size}`), style: { maxWidth: this.maxWidth } }, h("slot", { key: '992b81a264e71271efa83f6c9983a89c0b9e3311' }))), this.interval > 0 && this.visible && h("span", { key: '143151d5fe50640ba66fd34fc318ddc89746f303', class: "modal-interval-indicator" }, h("span", { key: '80bc1633fbff703a9efa753292176a121ad5caf7', style: { animationDuration: this.interval + 's' } })));
    }
    ;
    get el() { return getElement(this); }
    static get watchers() { return {
        "visible": ["watchVisible"]
    }; }
};
XModal.style = XModalStyle0;

export { XModal as x_modal };
