/*!
 * KoliBri - The accessible HTML-Standard
 */
import{a as i,b as t}from"./align-floating-elements-DTTpkCAK.js";import{v as s}from"./common-DEEjER7G.js";import{t as h,a as e}from"./tooltip-open-tracking-D3tCiiGP.js";import{c as o,n}from"./normalizers-pgU77mXp.js";import{a}from"./align-ChLoh-Dq.js";import{l as r}from"./label-DPd4-fag.js";import"./variant-quote-BMV8GZX8.js";import{B as l}from"./base-controller-CXhqh4cR.js";const f=new Set;let c=null;function u(i){if(c!==i){if(c){c.style.setProperty("z-index","999")}f.delete(i);f.add(i);i.style.setProperty("z-index","1000");c=i}}function m(i){if(!f.delete(i)){return}if(c===i){c=null;for(const i of f){c=i}if(c){c.style.setProperty("z-index","1000")}}}const d=o("align","top",(i=>{const t=n(i);if(a.includes(t)){return t}throw new Error(`Invalid align value: ${t}`)}),(i=>a.includes(i)));const p=o("badgeText","",n);const g=o("id","",n);const w={required:[r],optional:[d,p,g]};class T extends l{constructor(i){super(i,w);this.hasFocusIn=false;this.hasMouseIn=false;this.isHiddenForCurrentVisit=false;this.setTooltipElementRef=i=>{this.tooltipElement=i;if(this.tooltipElement){this.addListeners(this.tooltipElement)}};this.hideTooltipByEscape=i=>{if(i.key==="Escape"){this.hideTooltip()}};this.handleMouseEnter=()=>{const i=this.isNewVisit();this.hasMouseIn=true;if(i){this.isHiddenForCurrentVisit=false}this.showOrHideTooltip()};this.handleMouseLeave=()=>{this.hasMouseIn=false;this.resetHideFlag();this.showOrHideTooltip()};this.handleFocusIn=()=>{const i=this.isNewVisit();this.hasFocusIn=true;if(i){this.isHiddenForCurrentVisit=false}this.showOrHideTooltip()};this.handleFocusOut=()=>{this.hasFocusIn=false;this.resetHideFlag();this.showOrHideTooltip()}}componentWillLoad(i){this.watchLabel(i.label);this.watchAlign(i.align);this.watchBadgeText(i.badgeText);this.watchId(i.id)}watchLabel(i){r.apply(i,(i=>{this.setRenderProp("label",i)}))}watchAlign(i){d.apply(i,(i=>{this.setRenderProp("align",i)}))}watchBadgeText(i){p.apply(i,(i=>{this.setRenderProp("badgeText",i)}))}watchId(i){g.apply(i,(i=>{this.setRenderProp("id",i)}))}initContext(i){this.previousSibling=i}syncListeners(i,t,s=false){if(i){this.removeListeners(i)}if(t){if(s){this.previousSibling=t}this.addListeners(t)}}handleEventListeners(i){const t=i.previousElementSibling;this.syncListeners(this.previousSibling,t,true)}hideTooltip(){this.isHiddenForCurrentVisit=true;if(this.tooltipElement){m(this.tooltipElement);h();this.tooltipElement.classList.remove("show");this.tooltipElement.classList.add("hide");if(this.cleanupAutoPositioning){this.cleanupAutoPositioning();this.cleanupAutoPositioning=undefined}}s().removeEventListener("keyup",this.hideTooltipByEscape)}destroy(){clearTimeout(this.overFocusTimeout);if(this.previousSibling){this.removeListeners(this.previousSibling);this.previousSibling=undefined}if(this.tooltipElement){this.removeListeners(this.tooltipElement)}if(this.cleanupAutoPositioning){this.cleanupAutoPositioning();this.cleanupAutoPositioning=undefined}s().removeEventListener("keyup",this.hideTooltipByEscape)}isNewVisit(){return!this.hasMouseIn&&!this.hasFocusIn}resetHideFlag(){if(this.isNewVisit()){this.isHiddenForCurrentVisit=false}}async alignTooltip(){if(this.tooltipElement&&this.previousSibling){await i({align:this.getRenderProp("align"),arrowElement:this.tooltipElement.querySelector(".kol-tooltip__arrow"),floatingElement:this.tooltipElement,referenceElement:this.previousSibling})}}showTooltip(){if(this.isHiddenForCurrentVisit){return}if(this.previousSibling&&this.tooltipElement){u(this.tooltipElement);e();this.tooltipElement.classList.remove("hide");this.tooltipElement.classList.add("show");this.tooltipElement.style.setProperty("display","block");s().addEventListener("keyup",this.hideTooltipByEscape,{once:true});const i=this.previousSibling;const h=this.tooltipElement;this.cleanupAutoPositioning=t(i,h,(()=>{void this.alignTooltip()}))}}showOrHideTooltip(){clearTimeout(this.overFocusTimeout);this.overFocusTimeout=setTimeout((()=>{if(this.hasMouseIn||this.hasFocusIn){this.showTooltip()}else{this.hideTooltip()}}),300)}addListeners(i){i.addEventListener("mouseover",this.handleMouseEnter);i.addEventListener("mouseout",this.handleMouseLeave);i.addEventListener("focusin",this.handleFocusIn);i.addEventListener("focusout",this.handleFocusOut)}removeListeners(i){i.removeEventListener("mouseover",this.handleMouseEnter);i.removeEventListener("mouseout",this.handleMouseLeave);i.removeEventListener("focusin",this.handleFocusIn);i.removeEventListener("focusout",this.handleFocusOut)}}export{T};
//# sourceMappingURL=controller-oT8Y98Yc.js.map