import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { e as getTooltipElement, t as tinyMDtoHTML } from './helpers.js';
import { c as createPopper } from './popper.js';

const styleCss = "x-tooltip{display:inherit}x-tooltip-overlay{font-family:\"Poppins\", \"Arial\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", \"Liberation Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";background:var(--color-dark-tinted, #626262);color:var(--color-text-light, #FEFEFE);padding:4px 8px;font-size:0.9rem;border-radius:4px;display:none;-webkit-box-shadow:0 0 1em rgba(0, 0, 0, 0.2);box-shadow:0 0 1em rgba(0, 0, 0, 0.2);z-index:10000;position:relative;text-align:inherit}x-tooltip-overlay:empty{display:none}.is-dark-mode x-tooltip-overlay{background:var(--color-light-shade, #d8d8d8);color:var(--color-text, #4A4A4A)}x-tooltip-overlay[data-show]{display:block;-webkit-animation:0.4s fadeIn;animation:0.4s fadeIn}x-tooltip-overlay>p{margin:0px;font-family:\"Poppins\", \"Arial\", -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, \"Noto Sans\", \"Liberation Sans\", sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\"}x-tooltip-overlay .tooltip-arrow,x-tooltip-overlay .tooltip-arrow::before{position:absolute;width:8px;height:8px;z-index:-1}x-tooltip-overlay .tooltip-arrow::before{content:\"\";-webkit-transform:rotate(45deg);transform:rotate(45deg);background:var(--color-dark-tinted, #626262)}.is-dark-mode x-tooltip-overlay .tooltip-arrow::before{background:var(--color-light-shade, #d8d8d8)}x-tooltip-overlay[data-popper-placement^=top]>.tooltip-arrow{bottom:-4px}x-tooltip-overlay[data-popper-placement^=bottom]>.tooltip-arrow{top:-4px}x-tooltip-overlay[data-popper-placement^=left]>.tooltip-arrow{right:-4px}x-tooltip-overlay[data-popper-placement^=right]>.tooltip-arrow{left:-4px}";
const XTooltipStyle0 = styleCss;

const popperDefaultConfig = {
    placement: 'auto',
    modifiers: [
        {
            name: 'offset',
            options: {
                offset: [0, 4],
            },
        },
    ],
};
const showEvents = ['mouseenter'];
const hideEvents = ['mouseleave', 'blur'];
const XTooltip = /*@__PURE__*/ proxyCustomElement(class XTooltip extends HTMLElement {
    constructor() {
        super();
        this.__registerHost();
        this.content = undefined;
        this.align = 'top';
    }
    /**
     * On component did loaded hook
     */
    componentDidLoad() {
        this.tooltip = getTooltipElement();
        showEvents.forEach(event => {
            this.el.addEventListener(event, this.showHandler.bind(this));
        });
        hideEvents.forEach(event => {
            this.el.addEventListener(event, this.hideHandler.bind(this));
        });
    }
    /**
     * On component did destroyed hook
     */
    disconectedCallback() {
        showEvents.forEach(event => {
            this.el.removeEventListener(event, this.showHandler);
        });
        hideEvents.forEach(event => {
            this.el.removeEventListener(event, this.hideHandler);
        });
        if (this.popper) {
            this.popper.destroy();
        }
    }
    /**
     * Show tooltip overlay popper
     */
    showHandler() {
        this.tooltip.setAttribute('data-show', '');
        this.tooltip.querySelector('span').innerHTML = tinyMDtoHTML(this.content) || '';
        this.popper = createPopper(this.el, this.tooltip, Object.assign(Object.assign({}, popperDefaultConfig), { placement: this.align }));
    }
    /**
     * Hide tooltip overlay popper
     */
    hideHandler() {
        this.tooltip.removeAttribute('data-show');
        this.tooltip.querySelector('span').innerHTML = '';
        this.popper.destroy();
        this.popper = null;
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: 'b50b8a5bdb305699d7553b82ac2156ca7caa373d', "aria-label": this.content });
    }
    get el() { return this; }
    static get style() { return XTooltipStyle0; }
}, [0, "x-tooltip", {
        "content": [1],
        "align": [1]
    }]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["x-tooltip"];
    components.forEach(tagName => { switch (tagName) {
        case "x-tooltip":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, XTooltip);
            }
            break;
    } });
}

export { XTooltip as X, defineCustomElement as d };
