import{r as l,d as n,a as h,O as a,h as s,H as c,w as v}from"./index-DscFWUNz.js";import{v as d}from"./align-CyK0wp7d-DT9btF96.js";import{v as p}from"./show-DsV_Vx8g-SdAZ1_a3.js";import{a as m}from"./align-floating-elements-Bx4ukVlr-CFQB2kd1.js";import{c as r}from"./clsx-eK3rPvPS-BT_IL7Fz.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const g=(t,e)=>{v(t,"_on",o=>typeof o=="object"&&o!==null,new Set(["PopoverCallbacksPropType {Events.onClose}"]),e)},y=class{constructor(t){l(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._show=!1,this.state={_align:"top",_on:{},_show:!1,_visible:!1}}async showPopover(){this.addListenersToBody(),this.triggerElement&&this.popoverElement&&(await m({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,o,i;this.state=Object.assign(Object.assign({},this.state),{_visible:!1}),this._show=!1,(e=this.triggerElement)===null||e===void 0||e.focus(),this.removeListenersToBody(),(i=(o=this.state._on)===null||o===void 0?void 0:o.onClose)===null||i===void 0||i.call(o,t),this.host&&n(this.host,h.close)}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(c,{key:"53179ace5c0dfabbe1dd00ba8ddfe453ef55ccd5",ref:this.catchHostAndTriggerElement,class:"kol-popover"},s("div",{key:"f42aafe81aaa0a09526b4e9923a96133ee81c5d2",class:r("kol-popover__content",{"kol-popover__content--visible":this.state._visible}),ref:this.catchPopoverElement,hidden:!this.state._show},s("div",{key:"25719436c820c214a2e3c0fac47449f842c4f68c",class:r("kol-popover__arrow",`kol-popover__arrow--${this.state._align}`),ref:this.catchArrowElement}),s("slot",{key:"fff04758761fb36389c6698b17730b604981ca66"})))}validateAlign(t){d(this,t)}validateOn(t){g(this,t)}validateShow(t){p(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{y as kol_popover_wc};
//# sourceMappingURL=kol-popover-wc.entry-CPriy6s9.js.map
