import { r as registerInstance, h, H as Host, g as getElement } from './index-966f70a5.js';
import { c as cls } from './helpers-e48a05ff.js';
import { c as createPopper } from './popper-0fbeff6d.js';

const styleCss = "x-dropdown{display:inherit;text-align:inherit}x-dropdown .dropdown-container{position:absolute;visibility:hidden;z-index:-1}x-dropdown .dropdown-container.dropdown-show{z-index:10000;visibility:visible;-webkit-animation:0.4s fadeIn;animation:0.4s fadeIn}";
const XDropdownStyle0 = styleCss;

const popperDefaultConfig = {
    placement: 'auto',
    modifiers: [
        {
            name: 'offset',
            options: {
                offset: [0, 0],
            },
        },
    ],
};
const XDropdown = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.show = false;
        this.align = 'bottom';
        this.hover = false;
        this.syncWidth = false;
    }
    /**
     * Update popper setting on align change
     */
    onAlignWatch() {
        this.updatePopper();
    }
    /**
     * On component did loaded hook
     */
    componentDidLoad() {
        this.container = this.el.querySelector('.dropdown-container');
        this.updatePopper();
        this.el.addEventListener('mouseenter', () => {
            if (this.hover) {
                this.show = true;
            }
        });
        this.el.addEventListener('mouseleave', () => {
            if (this.hover) {
                this.show = false;
            }
        });
    }
    /**
     * On component did destroyed hook
     */
    disconectedCallback() {
        if (this.popper) {
            this.popper.destroy();
        }
    }
    /**
     * Update the popper instance or create
     */
    updatePopper() {
        this.popper = createPopper(this.el, this.container, Object.assign(Object.assign({}, popperDefaultConfig), { placement: this.align }));
        if (this.syncWidth) {
            this.container.style.maxWidth = `${this.el.offsetWidth}px`;
            this.container.style.width = '100%';
        }
        else {
            this.container.style.maxWidth = 'auto';
            this.container.style.width = 'auto';
        }
    }
    /**
     * Show tooltip overlay popper
     */
    async display(show) {
        this.show = show;
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: 'ecfd7bf191d9fe90c4157e6c05bb4074fb33fc57' }, h("slot", { key: '5a720b6b5f9dd78c76945dbbaa148dc19bf1e0fc' }), h("div", { key: 'b5205981b09d40a758f83354e82f815d74afa939', class: cls('dropdown-container', { 'dropdown-show': this.show, 'dropdown-hover': this.hover }) }, h("slot", { key: '6ab7f3925d9f4a2b6eadc999f7b23254282f2365', name: "dropdown" })));
    }
    get el() { return getElement(this); }
    static get watchers() { return {
        "align": ["onAlignWatch"],
        "show": ["onAlignWatch"]
    }; }
};
XDropdown.style = XDropdownStyle0;

export { XDropdown as x_dropdown };
