import{r as l,d as n,a as h,O as a,h as s,H as d,w as c}from"./index-BvWOSbaR.js";import{v}from"./align-CyK0wp7d-B1c2PRsI.js";import{v as p}from"./show-DsV_Vx8g-CV2f-OPT.js";import{a as m}from"./align-floating-elements-Bx4ukVlr-BjpcfWth.js";import{c as r}from"./clsx-eK3rPvPS-BT_IL7Fz.js";/*!
 * KoliBri - The accessible HTML-Standard
 */const g=(t,e)=>{c(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(d,{key:"73e96ffd3bd3e790af370c6b6c04b8000abd1ce2",ref:this.catchHostAndTriggerElement,class:"kol-popover"},s("div",{key:"5ed3a18bf6b76f8d607c17352fd9956f3cb3782c",class:r("kol-popover__content",{"kol-popover__content--visible":this.state._visible}),ref:this.catchPopoverElement,hidden:!this.state._show},s("div",{key:"aa1ca688f04b23b180c64b841a17ee6b3d6812b0",class:r("kol-popover__arrow",`kol-popover__arrow--${this.state._align}`),ref:this.catchArrowElement}),s("slot",{key:"d94f499e6fbbb7e855487d870cfca3ddfec7e495"})))}validateAlign(t){v(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-C9R7YZS-.js.map
