import{a as c,b as m}from"./align-floating-elements-58sFZOrL-D-p03Rue.js";import{C as o}from"./index-Di6F0tPl.js";import{t as f,a as E}from"./tooltip-open-tracking-D3tCiiGP-DFCvib6Z.js";import{c as n,n as l}from"./normalizers-C14RETgU-C323STio.js";import{a as r}from"./align-D3Z54kEL-DXjzhklK.js";import{l as h}from"./label-DK7sT-k5-DlQTN4B-.js";import"./variant-quote-DI6q8gPw-CeInbXEy.js";import{B as g}from"./base-controller-CXhqh4cR-D2BOZI1P.js";const s=new Set;function v(e){s.forEach(t=>{t.style.setProperty("z-index","999")}),s.add(e),e.style.setProperty("z-index","1000")}function L(e){if(s.delete(e),s.size>0){const t=Array.from(s).pop();t&&t.style.setProperty("z-index","1000")}}const a=n("align","top",e=>{const t=l(e);if(r.includes(t))return t;throw new Error(`Invalid align value: ${t}`)},e=>r.includes(e)),p=n("badgeText","",l),d=n("id","",l),T={required:[h],optional:[a,p,d]};class V extends g{constructor(t){super(t,T),this.hasFocusIn=!1,this.hasMouseIn=!1,this.isHiddenForCurrentVisit=!1,this.setTooltipElementRef=i=>{this.tooltipElement=i,this.tooltipElement&&this.addListeners(this.tooltipElement)},this.hideTooltipByEscape=i=>{i.key==="Escape"&&this.hideTooltip()},this.handleMouseEnter=()=>{const i=this.isNewVisit();this.hasMouseIn=!0,i&&(this.isHiddenForCurrentVisit=!1),this.showOrHideTooltip()},this.handleMouseLeave=()=>{this.hasMouseIn=!1,this.resetHideFlag(),this.showOrHideTooltip()},this.handleFocusIn=()=>{const i=this.isNewVisit();this.hasFocusIn=!0,i&&(this.isHiddenForCurrentVisit=!1),this.showOrHideTooltip()},this.handleFocusOut=()=>{this.hasFocusIn=!1,this.resetHideFlag(),this.showOrHideTooltip()}}componentWillLoad(t){this.watchLabel(t.label),this.watchAlign(t.align),this.watchBadgeText(t.badgeText),this.watchId(t.id)}watchLabel(t){h.apply(t,i=>{this.setRenderProp("label",i)})}watchAlign(t){a.apply(t,i=>{this.setRenderProp("align",i)})}watchBadgeText(t){p.apply(t,i=>{this.setRenderProp("badgeText",i)})}watchId(t){d.apply(t,i=>{this.setRenderProp("id",i)})}initContext(t){this.previousSibling=t}syncListeners(t,i,u=!1){t&&this.removeListeners(t),i&&(u&&(this.previousSibling=i),this.addListeners(i))}handleEventListeners(t){const i=t.previousElementSibling;this.syncListeners(this.previousSibling,i,!0)}hideTooltip(){this.isHiddenForCurrentVisit=!0,this.tooltipElement&&(L(this.tooltipElement),f(),this.tooltipElement.classList.remove("show"),this.tooltipElement.classList.add("hide"),this.cleanupAutoPositioning&&(this.cleanupAutoPositioning(),this.cleanupAutoPositioning=void 0)),o().removeEventListener("keyup",this.hideTooltipByEscape)}destroy(){clearTimeout(this.overFocusTimeout),this.previousSibling&&(this.removeListeners(this.previousSibling),this.previousSibling=void 0),this.tooltipElement&&this.removeListeners(this.tooltipElement),this.cleanupAutoPositioning&&(this.cleanupAutoPositioning(),this.cleanupAutoPositioning=void 0),o().removeEventListener("keyup",this.hideTooltipByEscape)}isNewVisit(){return!this.hasMouseIn&&!this.hasFocusIn}resetHideFlag(){this.isNewVisit()&&(this.isHiddenForCurrentVisit=!1)}async alignTooltip(){this.tooltipElement&&this.previousSibling&&await c({align:this.getRenderProp("align"),arrowElement:this.tooltipElement.querySelector(".kol-tooltip__arrow"),floatingElement:this.tooltipElement,referenceElement:this.previousSibling})}showTooltip(){if(!this.isHiddenForCurrentVisit&&this.previousSibling&&this.tooltipElement){v(this.tooltipElement),E(),this.tooltipElement.classList.remove("hide"),this.tooltipElement.classList.add("show"),this.tooltipElement.style.setProperty("display","block"),o().addEventListener("keyup",this.hideTooltipByEscape,{once:!0});const t=this.previousSibling,i=this.tooltipElement;this.cleanupAutoPositioning=m(t,i,()=>{this.alignTooltip()})}}showOrHideTooltip(){clearTimeout(this.overFocusTimeout),this.overFocusTimeout=setTimeout(()=>{this.hasMouseIn||this.hasFocusIn?this.showTooltip():this.hideTooltip()},300)}addListeners(t){t.addEventListener("mouseover",this.handleMouseEnter),t.addEventListener("mouseout",this.handleMouseLeave),t.addEventListener("focusin",this.handleFocusIn),t.addEventListener("focusout",this.handleFocusOut)}removeListeners(t){t.removeEventListener("mouseover",this.handleMouseEnter),t.removeEventListener("mouseout",this.handleMouseLeave),t.removeEventListener("focusin",this.handleFocusIn),t.removeEventListener("focusout",this.handleFocusOut)}}export{V as T};
//# sourceMappingURL=controller-Cf3CGZT--xMZZPtNM.js.map
