class t{static calculateAvailableSpace(t){const e=t.getBoundingClientRect(),a=window.innerHeight,o=window.innerWidth,s=a-e.bottom,i=e.top,n=o-e.right;return{spaceAbove:i,spaceBelow:s,spaceLeft:e.left,spaceRight:n,viewportHeight:a,viewportWidth:o}}static getOptimalPlacement(t){const{spaceAbove:e,spaceBelow:a,spaceLeft:o,spaceRight:s}=this.calculateAvailableSpace(t);return a>=200&&a>=e?"bottom":e>=200&&e>a?"top":s>=200&&s>=o?"right":o>=200?"left":"bottom"}static findBoundaryElements(t){const e=[];let a=t.parentElement;for(;a&&a!==document.body;){const t=window.getComputedStyle(a),o=t.overflow,s=t.overflowY,i=t.overflowX;"auto"!==o&&"scroll"!==o&&"auto"!==s&&"scroll"!==s&&"auto"!==i&&"scroll"!==i||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 o=e-(t.y+t.height),s=t.y;return a.startsWith("top")?Math.max(s-20,100):a.startsWith("bottom")?Math.max(o-20,100):(a.startsWith("left")||a.startsWith("right"),Math.max(Math.min(s,o)-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-dropdown-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(t,e){const{spaceAbove:a,spaceBelow:o,spaceLeft:s,spaceRight:i}=this.calculateAvailableSpace(e),n=t.startsWith("top"),l=t.startsWith("bottom"),r=t.startsWith("left"),c=t.startsWith("right");return!(n&&o>a)&&(!(l&&a>o)&&(!(r&&i>s)&&!(c&&s>i)))}static applyCollisionData(t,e,a){if(e.flip){const{overflows:o}=e.flip;if(t.setAttribute("data-placement",a),o&&o.length>0){const e=o.map((t=>t.placement)).join(",");t.setAttribute("data-overflow",e)}else t.removeAttribute("data-overflow")}if(e.shift){const{x:a,y:o}=e.shift;void 0===a||void 0===o||0===a&&0===o?t.removeAttribute("data-shift"):t.setAttribute("data-shift",`${a},${o}`)}if(e.size){const{availableWidth:a,availableHeight:o}=e.size;void 0!==a&&t.setAttribute("data-available-width",a.toString()),void 0!==o&&t.setAttribute("data-available-height",o.toString())}}}class e{static createPortalPanel(t){const e=t.shadowRoot?.querySelector(".dropdown__panel");if(!e){const e=t.querySelector("[slot]");if(!e||"trigger"===e.getAttribute("slot"))return document.createElement("div")}let a=e?.assignedElements({flatten:!0})||[];if(0===a.length){a=Array.from(t.children).filter((t=>{const e=t.getAttribute("slot");return!e||"trigger"!==e}))}const o=document.createElement("div");return o.className="dropdown__panel",o.setAttribute("part","panel"),o.setAttribute("aria-hidden","false"),o.setAttribute("aria-labelledby","dropdown"),a.forEach((t=>{const e=t.cloneNode(!0);o.appendChild(e)})),o}static updatePortalPanel(t,e){if(!t)return;t.innerHTML="";const a=e.shadowRoot?.querySelector(".dropdown__panel");let o=a?.assignedElements({flatten:!0})||[];if(0===o.length){o=Array.from(e.children).filter((t=>{const e=t.getAttribute("slot");return!e||"trigger"!==e}))}o.forEach((e=>{const a=e.cloneNode(!0);t.appendChild(a)}))}}class a{static setupPortalEventListeners(t,e){t&&(this.setupMenuSelectListeners(t,e),this.setupKeyDownListeners(t,e))}static setupMenuSelectListeners(t,e){t&&t.addEventListener("nile-select",(t=>{const a=t;e.handlePanelSelect&&e.handlePanelSelect(a)}))}static setupKeyDownListeners(t,e){t&&t.addEventListener("keydown",(t=>{e.handleKeyDown&&e.handleKeyDown(t)}))}}export{t as P,e as a,a as b};
