import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
import { e as getTooltipElement, t as tinyMDtoHTML } from './helpers.js';
import { c as computePosition, a as autoPlacement, f as flip, s as shift, o as offset, b as arrow } from './floating-ui.dom.esm.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:absolute;text-align:inherit;top:0;left:0;width:-webkit-max-content;width:-moz-max-content;width:max-content}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{position:absolute;background:var(--color-dark-tinted, #626262);width:8px;height:8px;-webkit-transform:rotate(45deg);transform:rotate(45deg)}.is-dark-mode x-tooltip-overlay .tooltip-arrow{background:var(--color-light-shade, #d8d8d8)}";
const XTooltipStyle0 = styleCss;

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);
        });
    }
    /**
     * Show tooltip overlay
     */
    showHandler() {
        this.tooltip.setAttribute('data-show', '');
        this.tooltip.querySelector('span').innerHTML = tinyMDtoHTML(this.content) || '';
        const arrowEl = this.tooltip.querySelector('.tooltip-arrow');
        computePosition(this.el, this.tooltip, {
            placement: this.align,
            middleware: [this.align == 'auto' ? autoPlacement() : flip(), shift({ padding: 10 }), offset(4), arrow({ element: arrowEl })],
        }).then(({ x, y, middlewareData, placement }) => {
            this.tooltip.style.left = `${x}px`;
            this.tooltip.style.top = `${y}px`;
            if (middlewareData.arrow) {
                const { x: arrowX, y: arrowY } = middlewareData.arrow;
                const staticSide = {
                    top: 'bottom',
                    right: 'left',
                    bottom: 'top',
                    left: 'right',
                }[placement.split('-')[0]];
                Object.assign(arrowEl.style, {
                    left: arrowX != null ? `${arrowX}px` : '',
                    top: arrowY != null ? `${arrowY}px` : '',
                    right: '',
                    bottom: '',
                    [staticSide]: '-4px',
                });
            }
        });
    }
    /**
     * Hide tooltip overlay
     */
    hideHandler() {
        setTimeout(() => {
            this.tooltip.removeAttribute('data-show');
            this.tooltip.querySelector('span').innerHTML = '';
        }, 50);
    }
    /**
     * Render element
     */
    render() {
        return h(Host, { key: '5a5634c258cb53ebbb84bf5381bdbd9727be30c9', "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 };
