import{h,Host}from"@stencil/core";import{TooltipUtil}from"../../utils/tooltip-util";export class OntoTooltip{constructor(){this.clearTooltipsForRemovedElements=t=>{for(const o of t)for(const t of Array.from(o.removedNodes))if(this.removeTooltipFromNode(t))return},this.removeTooltipFromNode=t=>{if(t instanceof HTMLElement){if(TooltipUtil.getTooltipInstance(t))return TooltipUtil.destroyTooltip(t),!0;t.childNodes.forEach(this.removeTooltipFromNode)}return!1}}onMouseover(t){const o=TooltipUtil.getTooltipTarget(t.target);o&&this.handleTooltipTargetShow(o);const e=TooltipUtil.getTooltip(t.target);e&&this.handleTooltipShow(e)}handleTooltipShow(t){const o=t.tooltipTarget;o&&this.handleTooltipTargetShow(o)}handleTooltipTargetShow(t){TooltipUtil.getOrCreateTooltipInstance(t).show()}onMouseout(t){const o=TooltipUtil.getTooltipTarget(t.target);o&&this.handleTooltipTargetHide(o,t.relatedTarget);const e=TooltipUtil.getTooltip(t.target);e&&this.handleTooltipHide(e,t.relatedTarget)}handleTooltipHide(t,o){const e=t.tooltipTarget;e&&(o&&t.contains(o)||this.handleTooltipTargetHide(e,o))}handleTooltipTargetHide(t,o){o&&(null==t?void 0:t.contains(o))||TooltipUtil.getTooltipInstance(t)&&TooltipUtil.destroyTooltip(t)}connectedCallback(){this.handleRemovedNodes()}disconnectedCallback(){var t;null===(t=this.observer)||void 0===t||t.disconnect()}render(){return h(Host,{key:"75eed5318bfdf3ace7e57d939aa3cf67f546862f"})}handleRemovedNodes(){this.observer=new MutationObserver(this.clearTooltipsForRemovedElements),this.observer.observe(document.body,{childList:!0,subtree:!0})}static get is(){return"onto-tooltip"}static get originalStyleUrls(){return{$:["onto-tooltip.scss"]}}static get styleUrls(){return{$:["onto-tooltip.css"]}}static get listeners(){return[{name:"mouseover",method:"onMouseover",target:"document",capture:!1,passive:!0},{name:"mouseout",method:"onMouseout",target:"document",capture:!1,passive:!0}]}}