import{r as t,c as o,h as i,H as e,g as s}from"./p-23a36bb6.js";import{FloatingManager as r}from"@sankhyalabs/core";const n=class{constructor(i){t(this,i),this.ezVisibilityChange=o(this,"ezVisibilityChange",7),this._firstRender=!0,this.innerClickTest=(t,o,i)=>{const e=[t];this.innerElement&&("string"==typeof this.innerElement?e.push(document.querySelector(`#${this.innerElement}`)):this.innerElement.forEach((t=>{e.push(document.querySelector(`#${t}`))})));const s=(null==i?void 0:i.composedPath())||[];for(var r=0;r<e.length;r++){let t=e[r];if(null!=t){if(s.includes(t))return!0;if(t.contains(o))return!0;if(i&&"nodeType"in(null==i?void 0:i.target)&&t.contains(i.target))return!0;if(t.shadowRoot&&t.shadowRoot.contains(o))return!0;if(t=this._host,t.lastElementChild.shadowRoot?t.lastElementChild.shadowRoot.contains(o):t.contains(o))return!0}}return!1},this.backClickListener=()=>{this.ezVisibilityChange.emit(!1)},this.autoClose=!0,this.boxWidth="fit-content",this.opened=void 0,this.innerElement=void 0,this.overlayType="light"}observeOpened(t,o){t!=o&&(o?this.hide():this.show(),this.ezVisibilityChange.emit(t))}async updatePosition(t,o){r.updateFloatPosition(this._box,this._container,{autoClose:this.autoClose,top:t,left:o,innerClickTest:this.innerClickTest,backClickListener:this.backClickListener})}async show(t,o){this.float({top:t,left:o})}async showUnder(t,o){t&&this._host?this.float(this.calculatePosition(t,Object.assign({verticalGap:0,horizontalGap:0,fromRight:!1},o))):this.show((null==o?void 0:o.verticalGap)?`${o.verticalGap}px`:void 0,(null==o?void 0:o.horizontalGap)?`${o.horizontalGap}px`:void 0)}calculatePosition(t,o){const i=this._host.getBoundingClientRect(),e=t.getBoundingClientRect(),s=`${(o.fromRight?i.right-e.right:e.x-i.x)+o.horizontalGap}px`;return{top:`${e.bottom-i.y+o.verticalGap}px`,left:o.fromRight?"":s,right:o.fromRight?s:""}}float(t){this._box.style.top="",this._box.style.left="",this._box.style.right="";const o="none"!==this.overlayType,i=`ez-scrim ez-scrim--${this.overlayType}`;let e=Object.assign(Object.assign({},t),{autoClose:this.autoClose,innerClickTest:this.innerClickTest,backClickListener:this.backClickListener});o&&(e=Object.assign(Object.assign({},e),{autoClose:!0,useOverlay:o,overlayClassName:i})),this._floatingID=r.float(this._box,this._container,e),this.opened=!0}async hide(){void 0!==this._floatingID&&(r.close(this._floatingID),this._floatingID=void 0,this.opened=!1)}componentDidRender(){this._firstRender&&(this._box.remove(),this._firstRender=!1)}render(){return i(e,null,i("section",{ref:t=>this._container=t},i("div",{class:"popover__box "+("fit-content"===this.boxWidth?"popover__box--fit-content":"popover__box--full-width"),ref:t=>this._box=t},i("slot",null))))}get _host(){return s(this)}static get watchers(){return{opened:["observeOpened"]}}};n.style=":host{--ez-popover__box--border-radius:var(--border--radius-medium, 12px);--ez-popover__box--box-shadow:var(--shadow, 0px 0px 16px 0px #000);--ez-popover__box--background-color:var(--background--xlight, #fff);--ez-popover__box--z-index:var(--most-visible, 3);position:relative;display:flex;user-select:none}.popover__box{z-index:var(--ez-popover__box--z-index);display:flex;flex-direction:column;height:fit-content;background-color:var(--ez-popover__box--background-color);border-radius:var(--ez-popover__box--border-radius);box-shadow:var(--ez-popover__box--box-shadow)}.popover__box--fit-content{width:fit-content}.popover__box--full-width{width:100%}";export{n as ez_popover}