import{B as t}from"../lit-html-39a6718c.esm.js";class e{static calculateAvailableSpace(t){const e=t.getBoundingClientRect(),a=window.innerHeight,s=a-e.bottom;return{spaceAbove:e.top,spaceBelow:s,viewportHeight:a}}static getOptimalPlacement(t){const{spaceAbove:e,spaceBelow:a}=this.calculateAvailableSpace(t);return a<200&&e>a?"top":"bottom"}static findBoundaryElements(t){const e=[];let a=t.parentElement;for(;a&&a!==document.body;){const t=window.getComputedStyle(a),s=t.overflow,i=t.overflowY,o=t.overflowX;"auto"!==s&&"scroll"!==s&&"auto"!==i&&"scroll"!==i&&"auto"!==o&&"scroll"!==o||e.push(a),(a.hasAttribute("data-floating-boundary")||a.classList.contains("floating-boundary")||a.classList.contains("scroll-container"))&&e.push(a),a=a.parentElement}return e.length>0?e:void 0}static calculateOptimalHeight(t,e,a){const s=e-(t.y+t.height),i=t.y;return i>s?Math.max(i-20,100):s>i?Math.max(s-20,100):Math.max(Math.min(i,s)-20,100)}static extractStylesAsCSS(t){return"string"==typeof t?t:Array.isArray(t)?t.map((t=>this.extractStylesAsCSS(t))).join("\n"):t&&"object"==typeof t&&t.cssText?t.cssText:""}static generateStyleId(){return`nile-auto-complete-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(t,e){const{spaceAbove:a,spaceBelow:s}=this.calculateAvailableSpace(e),i=t.startsWith("top"),o=t.startsWith("bottom");return!(i&&s>a)&&!(o&&a>s)}static applyCollisionData(t,e,a){if(e.flip){const{overflows:s}=e.flip;if(t.setAttribute("data-placement",a),s&&s.length>0){const e=s.map((t=>t.placement)).join(",");t.setAttribute("data-overflow",e)}else t.removeAttribute("data-overflow")}if(e.shift){const{x:a,y:s}=e.shift;void 0===a||void 0===s||0===a&&0===s?t.removeAttribute("data-shift"):t.setAttribute("data-shift",`${a},${s}`)}if(e.size){const{availableWidth:a,availableHeight:s}=e.size;void 0!==a&&t.setAttribute("data-available-width",a.toString()),void 0!==s&&t.setAttribute("data-available-height",s.toString())}}}class a{static createBaseMenu(t){const e=document.createElement("nile-menu");return e.id="content-menu",e.className=t.enableVirtualScroll?"virtualized__menu":"",t.enableVirtualScroll,e.setAttribute("exportparts","menu__items-wrapper:options__wrapper"),e}static addMenuItems(t,e){(e.menuItems||[]).forEach((a=>{const s=this.createMenuItem(a,e);t.appendChild(s)}))}static createMenuItem(e,a){const s=document.createElement("div"),i=a.getItemRenderFunction(e);return t(i,s),s.firstElementChild}static createPortalMenu(t){const e=this.createBaseMenu(t);return this.addMenuItems(e,t),e}static updatePortalMenuItems(t,e){if(!t)return;t.querySelectorAll("nile-menu-item").forEach((t=>t.remove())),this.addMenuItems(t,e)}}class s{static setupPortalEventListeners(t,e){t&&this.setupMenuSelectListeners(t,e)}static setupMenuSelectListeners(t,e){t&&t.addEventListener("nile-select",(t=>{const a=t;e.handleSelect&&e.handleSelect(a)}))}}export{e as P,a,s as b};
