import{r,P as a,h as s,H as l,w as n,i as h}from"./index-CJwtOLCA.js";import{a as d}from"./align-floating-elements-f88f945f-DNJFvZ9i.js";import{v}from"./align-bc8d98ac-DfD8j5LE.js";import{v as c}from"./show-82afe4f8-BURADImL.js";/*!
 * KoliBri - The accessible HTML-Standard
 */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:"7e8b70752711f74fe8e7a53588a178df9817ad70",ref:this.catchHostAndTriggerElement,class:"kol-popover"},s("div",{key:"d3f0349db15c6cc2cce0535cf19a73d583e2782a",class:{popover:!0,show:this.state._visible},ref:this.catchPopoverElement,hidden:!this.state._show},s("div",{key:"cd18e5bf5d0e99c242729e873fba3f39a0f40ab9",class:`arrow ${this.state._align}`,ref:this.catchArrowElement}),s("slot",{key:"1c77cad7f872746e56215a5e43508ed724e07545"})))}validateAlign(t){v(this,t)}validateOn(t){p(this,t)}validateShow(t){c(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-D_ta8pGE.js.map
