import{r,P as a,h as s,H as l,w as n,i as h}from"./index-BeCeuELg.js";import{a as d}from"./align-floating-elements-7a0eec66-BRtwkQ8l.js";import{v as c}from"./align-a1976178-CkMi2aRf.js";import{v}from"./show-316a9860-DLLl8Cq_.js";const p=(t,e)=>{n(t,"_on",i=>h(i),new Set(["PopoverCallbacksPropType {Events.onClose}"]),e)},_=class{constructor(t){r(this,t),this.hidePopoverByEscape=e=>{e.key==="Escape"&&this.hidePopover(e)},this.hidePopoverByClickOutside=e=>{this.host&&!this.host.contains(e.target)&&this.hidePopover(e)},this.catchHostAndTriggerElement=e=>{e&&(this.host=e,this.triggerElement=e.previousElementSibling)},this.catchPopoverElement=e=>{this.popoverElement=e},this.catchArrowElement=e=>{this.arrowElement=e},this._align="top",this._on=void 0,this._show=!1,this.state={_align:"top",_on:{},_show:!1,_visible:!1}}async showPopover(){this.addListenersToBody(),this.triggerElement&&this.popoverElement&&(await d({align:this._align,referenceElement:this.triggerElement,arrowElement:this.arrowElement,floatingElement:this.popoverElement}),this.state=Object.assign(Object.assign({},this.state),{_visible:!0}))}hidePopover(t){var e,i,o;this.state=Object.assign(Object.assign({},this.state),{_visible:!1}),this._show=!1,(e=this.triggerElement)===null||e===void 0||e.focus(),this.removeListenersToBody(),(o=(i=this.state._on)===null||i===void 0?void 0:i.onClose)===null||o===void 0||o.call(i,t)}addListenersToBody(){var t;const e=a().body;e.addEventListener("keyup",this.hidePopoverByEscape),e.addEventListener("click",this.hidePopoverByClickOutside),(t=document.scrollingElement)===null||t===void 0||t.addEventListener("scroll",()=>{this.showPopover()},{passive:!0})}removeListenersToBody(){var t;const e=a().body;e.removeEventListener("keyup",this.hidePopoverByEscape),e.removeEventListener("click",this.hidePopoverByClickOutside),(t=document.scrollingElement)===null||t===void 0||t.removeEventListener("scroll",()=>{this.showPopover()})}render(){return s(l,{key:"79e0b4ac6a89c18e8a43292c209b4d2cc44616f6",ref:this.catchHostAndTriggerElement,class:"kol-popover"},s("div",{key:"1b7db91dd28c40d01e3a3c5cf08021433178136a",class:{popover:!0,show:this.state._visible},ref:this.catchPopoverElement,hidden:!this.state._show},s("div",{key:"f566a81a9049d05ba9fbc3a1e71734ff3bfea05f",class:`arrow ${this.state._align}`,ref:this.catchArrowElement}),s("slot",{key:"8454a29da363209b8ac0438e43617ca87a79dd1c"})))}validateAlign(t){c(this,t)}validateOn(t){p(this,t)}validateShow(t){v(this,t),t&&this.showPopover()}componentWillLoad(){this.validateAlign(this._align),this.validateShow(this._show)}static get watchers(){return{_align:["validateAlign"],_on:["validateOn"],_show:["validateShow"]}}};export{_ as kol_popover_wc};
//# sourceMappingURL=kol-popover-wc.entry-BzVGi91G.js.map
