/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as i,h as t,H as s,g as e}from"./index-91489a9f.js";import{b as h,a}from"./align-floating-elements-db77d917.js";import{K as o}from"./Span-97af2595.js";import{i as n}from"./prop.validators-9feb1d92.js";import{g as d}from"./dev.utils-fab45cbc.js";import{v as l}from"./align-4719d626.js";import{v as r}from"./label-d0315384.js";import"./reuse-32931294.js";import"./tslib.es6-1173d062.js";import"./clsx-09a06a12.js";import"./Icon-936c5cfc.js";import"./component-names-a18a51c8.js";import"./InternalUnderlinedBadgeText-22278de8.js";import"./isObject-ffcbbb76.js";import"./index-da3e0c00.js";const f=(t,e)=>{n(t,"_badgeText",e)},c=(t,e)=>{n(t,"_id",e)},b=new Set;function u(t){b.forEach((t=>{t.style.setProperty("z-index","999")})),b.add(t),t.style.setProperty("z-index","1000")}function m(t){if(b.delete(t),b.size>0){const t=Array.from(b).pop();t&&t.style.setProperty("z-index","1000")}}const p=class{constructor(t){i(this,t),this.hasFocusIn=!1,this.hasMouseIn=!1,this.showTooltip=()=>{if(this.previousSibling&&this.tooltipElement){u(this.tooltipElement),this.tooltipElement.style.setProperty("display","block"),d().addEventListener("keyup",this.hideTooltipByEscape);const t=this.previousSibling,e=this.tooltipElement;this.cleanupAutoPositioning=h(t,e,(()=>{this.alignTooltip()}))}},this.hideTooltip=()=>{this.tooltipElement&&(m(this.tooltipElement),this.tooltipElement.style.setProperty("display","none"),this.tooltipElement.style.setProperty("visibility","hidden"),this.cleanupAutoPositioning&&(this.cleanupAutoPositioning(),this.cleanupAutoPositioning=void 0)),d().removeEventListener("keyup",this.hideTooltipByEscape)},this.hideTooltipByEscape=t=>{"Escape"===t.key&&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,e,i=!1)=>{t&&this.removeListeners(t),e&&(i&&(this.previousSibling=e),this.addListeners(e))},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 a({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 t(s,{key:"6b03bbbae8b6a083bcdb3b304e9985101a5be022",class:"kol-tooltip"},""!==this.state._label&&t("div",{key:"75fa23644f41ba3fde4e1be656ed89fe2bd5be9d",class:"kol-tooltip__floating",ref:this.catchTooltipElement},t("div",{key:"74d99d02b5d7557e4dc9c8d81880d76fbc23aa2d",class:"kol-tooltip__arrow",ref:this.catchArrowElement}),t(o,{key:"7a6b461ff6da4a292fabd08ab8a6bd90412a85fc",class:"kol-tooltip__content",id:this.state._id,badgeText:this._badgeText,label:this.state._label})))}validateBadgeText(t){f(this,t)}validateAlign(t){l(this,t)}validateId(t){c(this,t)}validateLabel(t){r(this,t,{required:!0})}componentWillLoad(){this.validateBadgeText(this._badgeText),this.validateAlign(this._align),this.validateId(this._id),this.validateLabel(this._label)}handleEventListeners(){var t;this.resyncListeners(this.previousSibling,null===(t=this.host)||void 0===t?void 0:t.previousElementSibling,!0),this.resyncListeners(this.tooltipElement,this.tooltipElement)}connectedCallback(){var t;this.previousSibling=null===(t=this.host)||void 0===t?void 0:t.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 e(this)}static get watchers(){return{_badgeText:["validateBadgeText"],_align:["validateAlign"],_id:["validateId"],_label:["validateLabel"]}}};export{p as kol_tooltip_wc};