import{r as t,c as i,h as s,H as o,g as e}from"./p-add854e8.js";import{c as h,a,o as n,b as l,f as r}from"./p-3aad9cd7.js";import{a as d}from"./p-479b8fc9.js";const p=class{constructor(s){t(this,s),this.ruxTooltipOpened=i(this,"ruxtooltipopened",7),this.ruxTooltipClosed=i(this,"ruxtooltipclosed",7),this.currentSlotted=void 0,this.hasTriggerSlot=!1,this.delegatedFocus=!1,this.message="",this.open=!1,this.delay=800,this.offset=8,this.placement="auto",this.disableAutoUpdate=!1,this.strategy="absolute"}handleDelay(){!isNaN(Number(this.delay))&&this.el.style.setProperty("--delay",`${Number(this.delay)}ms`)}handleOpen(){this.open?(this.content.style.display="block",this._startPositioner(),this.ruxTooltipOpened.emit()):(this.content.style.display="",this._stopPositioner(),this.ruxTooltipClosed.emit())}handlePlacement(){this._startPositioner()}handleKeypress(t){if("Escape"!==t.key)return;const i=this.trigger.matches(":hover"),s=this.triggerSlot.contains(document.activeElement);(i||s)&&this.open&&this.hide()}async show(){return this.open||(this.open=!0),this.open}async hide(){return this.open?(this.open=!1,!this.open):!this.open}connectedCallback(){this._handleSlotChange=this._handleSlotChange.bind(this),this._handleTooltipShow=this._handleTooltipShow.bind(this),this._handleTooltipHide=this._handleTooltipHide.bind(this)}disconnectedCallback(){this.el.shadowRoot.removeEventListener("slotchange",this._handleSlotChange)}componentWillLoad(){this._handleSlotChange()}componentDidLoad(){this.handleDelay(),this.handleOpen()}_position(){this.open&&this.triggerSlot&&this.content&&h(this.triggerSlot,this.content,{placement:this.placement,strategy:this.strategy,middleware:(()=>this.disableAutoUpdate?"auto"===this.placement?[n(this.offset),l({alignment:"start"})]:[n(this.offset)]:[n(this.offset),"auto"===this.placement?l({alignment:"start"}):r()])()}).then((({x:t,y:i})=>{Object.assign(this.content.style,{left:`${t}px`,top:`${i}px`,position:`${this.strategy}`})}))}_startPositioner(){this._stopPositioner(),this.open&&(this._position(),this.disableAutoUpdate||(this._positionerCleanup=a(this.triggerSlot,this.content,this._position.bind(this))))}_stopPositioner(){this._positionerCleanup&&(this._positionerCleanup(),this._positionerCleanup=void 0)}get triggerSlot(){var t,i;return void 0!==(null===(t=this.trigger)||void 0===t?void 0:t.querySelector("slot").assignedElements({flatten:!0})[0])?null===(i=this.trigger)||void 0===i?void 0:i.querySelector("slot").assignedElements({flatten:!0})[0]:this.trigger}get hasTrigger(){return!!this.trigger||this.hasTriggerSlot}_handleSlotChange(){this.hasTriggerSlot=d(this.el)}_handleTooltipShow(){this.open||(this.open=!0)}_handleTooltipHide(){this.open&&(this.open=!1)}render(){const{_handleSlotChange:t,_handleTooltipShow:i,_handleTooltipHide:e}=this;return s(o,null,s("span",{onMouseEnter:i,onMouseLeave:e,onFocusin:i,onFocusout:e},s("span",{class:"rux-tooltip__trigger",part:"trigger-container",ref:t=>this.trigger=t,"aria-describedby":"tooltip"},s("slot",{onSlotchange:t})),s("span",{"aria-hidden":this.open?"false":"true",class:{tooltip:!0,hidden:!this.open},id:"tooltip",role:"tooltip",part:"container",ref:t=>this.content=t},this.message)))}get el(){return e(this)}static get watchers(){return{delay:["handleDelay"],open:["handleOpen"],placement:["handlePlacement"]}}};p.style=":host{--delay:800ms}*{box-sizing:border-box}span{display:contents}.tooltip{display:inline-block;background:var(--tooltip-color-background, #3c3e42);padding:calc(var(--spacing-1, 0.25rem) / 2) var(--spacing-2, 0.5rem);color:var(--tooltip-color-text, #ffffff);width:fit-content;border-radius:var(--tooltip-radius, 1px);z-index:100;width:max-content;position:absolute;top:0;left:0;opacity:1;visibility:visible;transition:opacity 200ms ease-in;font-size:var(--font-body-2-font-size, 0.875rem);line-height:var(--font-body-2-line-height, calc(20 / 14));-webkit-user-select:none;user-select:none}.rux-tooltip__trigger{display:inline;flex-basis:100%}:host([open]) .tooltip{transition-delay:var(--delay);transition-property:opacity}.hidden{opacity:0 !important;visibility:hidden}";export{p as rux_tooltip}