import{__decorate as i}from"tslib";import{s as t}from"./nile-tooltip.css.esm.js";import"../nile-popup/nile-popup.esm.js";import{c as s,s as e,a as o}from"../internal/animate.esm.js";import{classMap as h}from"lit/directives/class-map.js";import{query as a,property as n,customElement as l}from"lit/decorators.js";import{s as r,g as p}from"../utilities/animation-registry.esm.js";import{html as d}from"lit";import{w as c}from"../internal/event.esm.js";import{w as m}from"../internal/watch.esm.js";import{N as u}from"../internal/nile-element.esm.js";import{V as f}from"../utilities/visibility-manager.esm.js";import"../floating-ui.dom-cc9126da.esm.js";import"../nile-popup/nile-popup.css.esm.js";import"../internal/accessibility/a11y.state.enum.esm.js";import"../internal/accessibility/a11y.property.enum.esm.js";import"../internal/accessibility/role.enum.esm.js";let y=class extends u{constructor(){super(...arguments),this.content="",this.size="small",this.placement="top",this.disabled=!1,this.distance=8,this.open=!1,this.skidding=0,this.trigger="hover focus",this.hoist=!1,this.enableVisibilityEffect=!1,this.enableTabClose=!1}static get styles(){return[t]}connectedCallback(){super.connectedCallback(),this.handleBlur=this.handleBlur.bind(this),this.handleClick=this.handleClick.bind(this),this.handleFocus=this.handleFocus.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleMouseOver=this.handleMouseOver.bind(this),this.handleMouseOut=this.handleMouseOut.bind(this),this.updateComplete.then((()=>{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)}))}firstUpdated(){this.body.hidden=!this.open,this.open&&(this.popup.active=!0,this.popup.reposition());const i=this.renderRoot.querySelector("slot:not([name])"),t=i?.assignedElements({flatten:!0})[0];this.visibilityManager=new f({host:this,target:t||null,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.open,onAnchorOutOfView:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(i,t)=>this.emit(`nile-${i}`,t)})}disconnectedCallback(){super.disconnectedCallback(),this.visibilityManager?.cleanup(),this.removeEventListener("blur",this.handleBlur,!0),this.removeEventListener("focus",this.handleFocus,!0),this.removeEventListener("click",this.handleClick),this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("mouseover",this.handleMouseOver),this.removeEventListener("mouseout",this.handleMouseOut)}handleBlur(){this.hasTrigger("focus")&&this.hide()}handleClick(){this.hasTrigger("click")&&(this.open?this.hide():this.show())}handleFocus(){this.hasTrigger("focus")&&this.show()}handleKeyDown(i){this.open&&"Escape"===i.key&&(i.stopPropagation(),this.hide())}handleMouseOver(){if(this.hasTrigger("hover")){const i=s(getComputedStyle(this).getPropertyValue("--show-delay"));clearTimeout(this.hoverTimeout),this.hoverTimeout=window.setTimeout((()=>this.show()),i)}}handleMouseOut(){if(this.hasTrigger("hover")){const i=s(getComputedStyle(this).getPropertyValue("--hide-delay"));clearTimeout(this.hoverTimeout),this.hoverTimeout=window.setTimeout((()=>this.hide()),i)}}hasTrigger(i){return this.trigger.split(" ").includes(i)}async handleOpenChange(){if(this.open){if(this.visibilityManager?.setup(),this.disabled)return;this.emit("nile-show"),await e(this.body),this.body.hidden=!1,this.popup.active=!0;const{keyframes:i,options:t}=p(this,"tooltip.show",{dir:""});await o(this.popup.popup,i,t),this.emit("nile-after-show")}else{this.visibilityManager?.cleanup(),this.emit("nile-hide"),await e(this.body);const{keyframes:i,options:t}=p(this,"tooltip.hide",{dir:""});await o(this.popup.popup,i,t),this.popup.active=!1,this.body.hidden=!0,this.emit("nile-after-hide")}}async handleOptionsChange(){this.hasUpdated&&(await this.updateComplete,this.popup.reposition())}handleDisabledChange(){this.disabled&&this.open&&this.hide()}async show(){if(!this.open&&this.content?.trim().length)return this.open=!0,c(this,"nile-after-show")}async hide(){if(this.open)return this.open=!1,c(this,"nile-after-hide")}render(){return d`
      <nile-popup
        part="base"
        exportparts="
          popup:base__popup,
          arrow:base__arrow
        "
        class=${h({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>

        <slot
          name="content"
          part="body"
          id="tooltip"
          class=${h({tooltip__body:!0,"tooltip__body--large":"large"===this.size})}
          role="tooltip"
          aria-live=${this.open?"polite":"off"}
        >
          ${this.content}
        </slot>
      </nile-popup>
    `}};i([a("slot:not([name])")],y.prototype,"defaultSlot",void 0),i([a(".tooltip__body")],y.prototype,"body",void 0),i([a("nile-popup")],y.prototype,"popup",void 0),i([n({type:String,reflect:!0})],y.prototype,"content",void 0),i([n({reflect:!0})],y.prototype,"size",void 0),i([n()],y.prototype,"placement",void 0),i([n({type:Boolean,reflect:!0})],y.prototype,"disabled",void 0),i([n({type:Number})],y.prototype,"distance",void 0),i([n({type:Boolean,reflect:!0})],y.prototype,"open",void 0),i([n({type:Number})],y.prototype,"skidding",void 0),i([n()],y.prototype,"trigger",void 0),i([n({type:Boolean})],y.prototype,"hoist",void 0),i([n({type:Boolean,reflect:!0})],y.prototype,"enableVisibilityEffect",void 0),i([n({type:Boolean,reflect:!0})],y.prototype,"enableTabClose",void 0),i([m("open",{waitUntilFirstUpdate:!0})],y.prototype,"handleOpenChange",null),i([m(["content","distance","hoist","placement","skidding"])],y.prototype,"handleOptionsChange",null),i([m("disabled")],y.prototype,"handleDisabledChange",null),y=i([l("nile-tooltip")],y),r("tooltip.show",{keyframes:[{opacity:0,scale:.8},{opacity:1,scale:1}],options:{duration:150,easing:"ease"}}),r("tooltip.hide",{keyframes:[{opacity:1,scale:1},{opacity:0,scale:.8}],options:{duration:150,easing:"ease"}});export{y as N};
