import{r as a,P as n,h as o,d as h,H as d,m as r,t as p}from"./index-BeCeuELg.js";import{b as c,a as u}from"./align-floating-elements-7a0eec66-BRtwkQ8l.js";import{t as v,a as m}from"./tooltip-open-tracking-23a84b19-DRkgcff2.js";import{v as f}from"./badge-text-3017b607-DxlOFfpe.js";import{v as E}from"./align-a1976178-CkMi2aRf.js";import{v as g}from"./label-3757689e-D7ErDa5R.js";const b=(e,t)=>{p(e,"_id",t)},s=new Set;function L(e){s.forEach(t=>{t.style.setProperty("z-index","999")}),s.add(e),e.style.setProperty("z-index","1000")}function T(e){if(s.delete(e),s.size>0){const t=Array.from(s).pop();t&&t.style.setProperty("z-index","1000")}}const F=class{constructor(e){a(this,e),this.hasFocusIn=!1,this.hasMouseIn=!1,this.showTooltip=()=>{if(this.previousSibling&&this.tooltipElement){L(this.tooltipElement),v(),this.tooltipElement.classList.remove("hide"),this.tooltipElement.classList.add("show"),this.tooltipElement.style.setProperty("display","block"),n().addEventListener("keyup",this.hideTooltipByEscape,{once:!0});const t=this.previousSibling,i=this.tooltipElement;this.cleanupAutoPositioning=c(t,i,()=>{this.alignTooltip()})}},this.hideTooltip=()=>{this.tooltipElement&&(T(this.tooltipElement),m(),this.tooltipElement.classList.remove("show"),this.tooltipElement.classList.add("hide"),this.cleanupAutoPositioning&&(this.cleanupAutoPositioning(),this.cleanupAutoPositioning=void 0)),n().removeEventListener("keyup",this.hideTooltipByEscape)},this.hideTooltipByEscape=t=>{t.key==="Escape"&&this.hideTooltip()},this.addListeners=t=>{t.addEventListener("mouseenter",this.handleMouseEnter.bind(this)),t.addEventListener("mouseleave",this.handleMouseLeave.bind(this)),t.addEventListener("focusin",this.handleFocusIn.bind(this)),t.addEventListener("focusout",this.handleFocusOut.bind(this))},this.removeListeners=t=>{t.removeEventListener("mouseenter",this.handleMouseEnter.bind(this)),t.removeEventListener("mouseleave",this.handleMouseLeave.bind(this)),t.removeEventListener("focusin",this.handleFocusIn.bind(this)),t.removeEventListener("focusout",this.handleFocusOut.bind(this))},this.resyncListeners=(t,i,l=!1)=>{t&&this.removeListeners(t),i&&(l&&(this.previousSibling=i),this.addListeners(i))},this.catchTooltipElement=t=>{this.tooltipElement=t},this.catchArrowElement=t=>{this.arrowElement=t},this.showOrHideTooltip=()=>{clearTimeout(this.overFocusTimeout),this.overFocusTimeout=setTimeout(()=>{this.hasMouseIn||this.hasFocusIn?this.showTooltip():this.hideTooltip()},300)},this._badgeText=void 0,this._align="top",this._id=void 0,this._label=void 0,this.state={_align:"top",_label:""}}async alignTooltip(){this.tooltipElement&&this.previousSibling&&await u({align:this._align,referenceElement:this.previousSibling,arrowElement:this.arrowElement,floatingElement:this.tooltipElement})}handleMouseEnter(){this.hasMouseIn=!0,this.showOrHideTooltip()}handleMouseLeave(){this.hasMouseIn=!1,this.showOrHideTooltip()}handleFocusIn(){this.hasFocusIn=!0,this.showOrHideTooltip()}handleFocusOut(){this.hasFocusIn=!1,this.showOrHideTooltip()}render(){return o(d,{key:"2835bd993b3e9237c0552e69c688f782a3d38ad8",class:"kol-tooltip-wc"},o("div",{key:"d155ebf8e5b057df516b3878fcbc7631d62ce0e4",class:"tooltip-floating",hidden:this.state._label.length===0,ref:this.catchTooltipElement},o("div",{key:"eadf9d9d29b5e0d6748b86db1d0019315d43bef6",class:"tooltip-area tooltip-arrow",ref:this.catchArrowElement}),o(h,{key:"d217f7c393c63b9f323cec887051001d322912ff",class:"tooltip-area tooltip-content",id:this.state._id,_badgeText:this._badgeText,_label:this.state._label})))}validateBadgeText(e){f(this,e)}validateAlign(e){E(this,e)}validateId(e){b(this,e)}validateLabel(e){g(this,e,{required:!0})}componentWillLoad(){this.validateBadgeText(this._badgeText),this.validateAlign(this._align),this.validateId(this._id),this.validateLabel(this._label)}handleEventListeners(){var e;this.resyncListeners(this.previousSibling,(e=this.host)===null||e===void 0?void 0:e.previousElementSibling,!0),this.resyncListeners(this.tooltipElement,this.tooltipElement)}connectedCallback(){var e;this.previousSibling=(e=this.host)===null||e===void 0?void 0:e.previousElementSibling}componentDidRender(){this.handleEventListeners()}disconnectedCallback(){this.previousSibling&&(this.removeListeners(this.previousSibling),this.previousSibling=void 0),this.tooltipElement&&this.removeListeners(this.tooltipElement),this.cleanupAutoPositioning&&this.cleanupAutoPositioning()}get host(){return r(this)}static get watchers(){return{_badgeText:["validateBadgeText"],_align:["validateAlign"],_id:["validateId"],_label:["validateLabel"]}}};export{F as kol_tooltip_wc};
//# sourceMappingURL=kol-tooltip-wc.entry-BEIKJZ37.js.map
