import{tooltip_styles_default as t}from"./chunk.NGU6VN5C.js";import{SlPopup as e}from"./chunk.NS3JH2ZN.js";import{getAnimation as i,setDefaultAnimation as s}from"./chunk.STXFIMXZ.js";import{waitForEvent as o}from"./chunk.B4BZKR24.js";import{animateTo as h,parseDuration as p,stopAnimations as a}from"./chunk.W5IOVX7A.js";import{LocalizeController as n}from"./chunk.2A3352EO.js";import{watch as r}from"./chunk.C7FWPEOY.js";import{ShoelaceElement as d}from"./chunk.Z7XDKKOD.js";import{__decorateClass as l}from"./chunk.6M63UXML.js";import{classMap as c}from"../../../../lit/directives/class-map.js";import{html as u}from"../../../../lit/index.js";import{property as m,query as y}from"../../../../lit/decorators.js";var f=class extends d{constructor(){super(),this.localize=new n(this),this.content="",this.placement="top",this.disabled=!1,this.distance=8,this.open=!1,this.skidding=0,this.trigger="hover focus",this.hoist=!1,this.handleBlur=()=>{this.hasTrigger("focus")&&this.hide()},this.handleClick=()=>{this.hasTrigger("click")&&(this.open?this.hide():this.show())},this.handleFocus=()=>{this.hasTrigger("focus")&&this.show()},this.handleKeyDown=t=>{this.open&&"Escape"===t.key&&(t.stopPropagation(),this.hide())},this.handleMouseOver=()=>{if(this.hasTrigger("hover")){const t=p(getComputedStyle(this).getPropertyValue("--show-delay"));clearTimeout(this.hoverTimeout),this.hoverTimeout=window.setTimeout((()=>this.show()),t)}},this.handleMouseOut=()=>{if(this.hasTrigger("hover")){const t=p(getComputedStyle(this).getPropertyValue("--hide-delay"));clearTimeout(this.hoverTimeout),this.hoverTimeout=window.setTimeout((()=>this.hide()),t)}},this.addEventListener("blur",this.handleBlur,!0),this.addEventListener("focus",this.handleFocus,!0),this.addEventListener("click",this.handleClick),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("mouseover",this.handleMouseOver),this.addEventListener("mouseout",this.handleMouseOut)}connectedCallback(){super.connectedCallback()}firstUpdated(){this.body.hidden=!this.open,this.open&&(this.popup.active=!0,this.popup.reposition())}hasTrigger(t){return this.trigger.split(" ").includes(t)}async handleOpenChange(){if(this.open){if(this.disabled)return;this.emit("sl-show"),await a(this.body),this.body.hidden=!1,this.popup.active=!0;const{keyframes:t,options:e}=i(this,"tooltip.show",{dir:this.localize.dir()});await h(this.popup.popup,t,e),this.emit("sl-after-show")}else{this.emit("sl-hide"),await a(this.body);const{keyframes:t,options:e}=i(this,"tooltip.hide",{dir:this.localize.dir()});await h(this.popup.popup,t,e),this.popup.active=!1,this.body.hidden=!0,this.emit("sl-after-hide")}}async handleOptionsChange(){this.hasUpdated&&(await this.updateComplete,this.popup.reposition())}handleDisabledChange(){this.disabled&&this.open&&this.hide()}async show(){if(!this.open)return this.open=!0,o(this,"sl-after-show")}async hide(){if(this.open)return this.open=!1,o(this,"sl-after-hide")}render(){return u`
      <sl-popup
        part="base"
        exportparts="
          popup:base__popup,
          arrow:base__arrow
        "
        class=${c({tooltip:!0,"tooltip--open":this.open})}
        placement=${this.placement}
        distance=${this.distance}
        skidding=${this.skidding}
        strategy=${this.hoist?"fixed":"absolute"}
        flip
        shift
        arrow
      >
        ${""}
        <slot slot="anchor" aria-describedby="tooltip"></slot>

        ${""}
        <div part="body" id="tooltip" class="tooltip__body" role="tooltip" aria-live=${this.open?"polite":"off"}>
          <slot name="content">${this.content}</slot>
        </div>
      </sl-popup>
    `}};f.styles=t,f.dependencies={"sl-popup":e},l([y("slot:not([name])")],f.prototype,"defaultSlot",2),l([y(".tooltip__body")],f.prototype,"body",2),l([y("sl-popup")],f.prototype,"popup",2),l([m()],f.prototype,"content",2),l([m()],f.prototype,"placement",2),l([m({type:Boolean,reflect:!0})],f.prototype,"disabled",2),l([m({type:Number})],f.prototype,"distance",2),l([m({type:Boolean,reflect:!0})],f.prototype,"open",2),l([m({type:Number})],f.prototype,"skidding",2),l([m()],f.prototype,"trigger",2),l([m({type:Boolean})],f.prototype,"hoist",2),l([r("open",{waitUntilFirstUpdate:!0})],f.prototype,"handleOpenChange",1),l([r(["content","distance","hoist","placement","skidding"])],f.prototype,"handleOptionsChange",1),l([r("disabled")],f.prototype,"handleDisabledChange",1),s("tooltip.show",{keyframes:[{opacity:0,scale:.8},{opacity:1,scale:1}],options:{duration:150,easing:"ease"}}),s("tooltip.hide",{keyframes:[{opacity:1,scale:1},{opacity:0,scale:.8}],options:{duration:150,easing:"ease"}});export{f as SlTooltip};