'use strict';

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

const index = require('./index-292cc870.js');
const helpers = require('./helpers-8ee23f51.js');
const popper = require('./popper-31badbf8.js');

const styleCss = "x-dropdown{display:inherit;text-align:inherit}x-dropdown .dropdown-container{position:absolute;z-index:10000}x-dropdown .dropdown-container.dropdown-show{left:initial;-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) {
        index.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 = 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 index.h(index.Host, { key: 'ecfd7bf191d9fe90c4157e6c05bb4074fb33fc57' }, index.h("slot", { key: '5a720b6b5f9dd78c76945dbbaa148dc19bf1e0fc' }), index.h("div", { key: 'b5205981b09d40a758f83354e82f815d74afa939', class: helpers.cls('dropdown-container', { 'dropdown-show': this.show, 'dropdown-hover': this.hover }) }, index.h("slot", { key: '6ab7f3925d9f4a2b6eadc999f7b23254282f2365', name: "dropdown" })));
    }
    get el() { return index.getElement(this); }
    static get watchers() { return {
        "align": ["onAlignWatch"],
        "show": ["onAlignWatch"]
    }; }
};
XDropdown.style = XDropdownStyle0;

exports.x_dropdown = XDropdown;
