import { h } from "@stencil/core";
export class Tooltip {
    constructor() {
        this.isTooltipVisible = false;
        this.position = 'top';
        this.triggerOnClick = false;
        this.handleEllipsisClick = this.handleEllipsisClick.bind(this);
        this.handleFocusOut = this.handleFocusOut.bind(this);
    }
    setTooltipVisible(isTooltipVisible) {
        this.isTooltipVisible = isTooltipVisible;
        this.triggerRender.emit(this.isTooltipVisible);
    }
    handleEllipsisClick(event) {
        if (!this.triggerOnClick) {
            return;
        }
        event.preventDefault();
        this.setTooltipVisible(!this.isTooltipVisible);
    }
    handleFocusOut(event) {
        const relatedTarget = event.relatedTarget;
        const currentTarget = event.currentTarget;
        if (!currentTarget.contains(relatedTarget)) {
            this.setTooltipVisible(false);
        }
    }
    handleMouseEvent(isTooltipVisible) {
        if (this.triggerOnClick) {
            return;
        }
        return (event) => {
            event.preventDefault();
            this.setTooltipVisible(isTooltipVisible);
        };
    }
    render() {
        return (h("div", { key: '0013a24cab1b0e1de411f02163918c589423324a', onClick: this.handleEllipsisClick, onMouseEnter: this.handleMouseEvent(true), onMouseLeave: this.handleMouseEvent(false), class: { tooltip: true, [this.class]: Boolean(this.class) } }, this.isTooltipVisible && (h("div", { key: '0fd190698331e70f5fce638ef5c2d9aaa4f951f6', class: { 'tooltip-content-wrapper': true, [this.position]: true } }, h("div", { key: '30be2b6a37dfb7585eb2160cf53a8b764be3f206', class: { 'tooltip-content': true, [this.position]: true }, tabIndex: -1, onFocusout: this.handleFocusOut, onClick: (event) => event.stopPropagation() }, h("slot", { key: '3e469ed31c5d0df9c43ce47adf299d5d31a4f1d2' })))), h("span", { key: '23e41c675de718a6f2a94c64fabb91e34baa15c0', class: "tooltip-trigger" }, this.trigger)));
    }
    static get is() { return "mvx-tooltip"; }
    static get encapsulation() { return "shadow"; }
    static get originalStyleUrls() {
        return {
            "$": ["tooltip.scss"]
        };
    }
    static get styleUrls() {
        return {
            "$": ["tooltip.css"]
        };
    }
    static get properties() {
        return {
            "position": {
                "type": "string",
                "attribute": "position",
                "mutable": false,
                "complexType": {
                    "original": "'top' | 'bottom'",
                    "resolved": "\"bottom\" | \"top\"",
                    "references": {}
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "'top'"
            },
            "triggerOnClick": {
                "type": "boolean",
                "attribute": "trigger-on-click",
                "mutable": false,
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "defaultValue": "false"
            },
            "trigger": {
                "type": "unknown",
                "attribute": "trigger",
                "mutable": false,
                "complexType": {
                    "original": "HTMLElement",
                    "resolved": "HTMLElement",
                    "references": {
                        "HTMLElement": {
                            "location": "global",
                            "id": "global::HTMLElement"
                        }
                    }
                },
                "required": false,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            },
            "class": {
                "type": "string",
                "attribute": "class",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false
            }
        };
    }
    static get states() {
        return {
            "isTooltipVisible": {}
        };
    }
    static get events() {
        return [{
                "method": "triggerRender",
                "name": "triggerRender",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "boolean",
                    "resolved": "boolean",
                    "references": {}
                }
            }];
    }
}
//# sourceMappingURL=tooltip.js.map
