/*!
 * KoliBri - The accessible HTML-Standard
 */
import{r as i,h as s,H as t}from"./index-2ae1c631.js";import{a as e}from"./align-floating-elements-db77d917.js";import{c as o}from"./clsx-09a06a12.js";import{d as a,K as l}from"./events-5adf6b62.js";import{w as h}from"./prop.validators-9feb1d92.js";import{g as r}from"./dev.utils-fab45cbc.js";import{v as n}from"./align-4719d626.js";import{v as c}from"./show-484b637e.js";import"./reuse-32931294.js";import"./index-da3e0c00.js";const d=(e,t)=>{h(e,"_on",(e=>"object"==typeof e&&null!==e),new Set(["PopoverCallbacksPropType {Events.onClose}"]),t)},f=class{constructor(e){i(this,e),this.hidePopoverByEscape=e=>{"Escape"===e.key&&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 e({align:this._align,referenceElement:this.triggerElement,arrowElement:this.arrowElement,floatingElement:this.popoverElement}),this.state=Object.assign(Object.assign({},this.state),{_visible:!0}))}hidePopover(e){var t,s,o;this.state=Object.assign(Object.assign({},this.state),{_visible:!1}),this._show=!1,null===(t=this.triggerElement)||void 0===t||t.focus(),this.removeListenersToBody(),null===(o=null===(s=this.state._on)||void 0===s?void 0:s.onClose)||void 0===o||o.call(s,e),this.host&&a(this.host,l.close)}addListenersToBody(){var e;const t=r().body;t.addEventListener("keyup",this.hidePopoverByEscape),t.addEventListener("click",this.hidePopoverByClickOutside),null===(e=document.scrollingElement)||void 0===e||e.addEventListener("scroll",(()=>{this.showPopover()}),{passive:!0})}removeListenersToBody(){var e;const t=r().body;t.removeEventListener("keyup",this.hidePopoverByEscape),t.removeEventListener("click",this.hidePopoverByClickOutside),null===(e=document.scrollingElement)||void 0===e||e.removeEventListener("scroll",(()=>{this.showPopover()}))}render(){return s(t,{key:"6e414db89865e4faced8091f9f4484077f903033",ref:this.catchHostAndTriggerElement,class:"kol-popover"},s("div",{key:"64a38574bf8ca2878f871846f9985eef4f0b3394",class:o("kol-popover__content",{"kol-popover__content--visible":this.state._visible}),ref:this.catchPopoverElement,hidden:!this.state._show},s("div",{key:"e2fe3722133cc1bc20be4a7ccfc45e0622442892",class:o("kol-popover__arrow",`kol-popover__arrow--${this.state._align}`),ref:this.catchArrowElement}),s("slot",{key:"9fba7bbfd2879e01da7c15f026227671bfb4c171"})))}validateAlign(e){n(this,e)}validateOn(e){d(this,e)}validateShow(e){c(this,e),e&&this.showPopover()}componentWillLoad(){this.validateAlign(this._align),this.validateShow(this._show)}static get watchers(){return{_align:["validateAlign"],_on:["validateOn"],_show:["validateShow"]}}};export{f as kol_popover_wc};