import{r as i,c as s,h as t,H as e,g as h}from"./p-1617f73a.js";const d=class{constructor(t){i(this,t);this.dropdownchange=s(this,"dropdownchange",7);this.close=s(this,"close",7);this.focusedIndex=-1;this.selectedIndex=-1;this.animationDuration=75;this.dropdownId=undefined;this.shown=undefined;this.label=undefined;this.position=undefined;this.variant=undefined;this.activeDescendantId=undefined}get slotEls(){var i,s,t;if(!this._slotEls){const e=(i=this.hostEl.shadowRoot)===null||i===void 0?void 0:i.querySelector("slot");const h=(s=e.assignedElements)===null||s===void 0?void 0:s.call(e)[0];this._slotEls=Array.from((t=h===null||h===void 0?void 0:h.children)!==null&&t!==void 0?t:[])}return this._slotEls}passDownProps(i,s){i===null||i===void 0?void 0:i.setAttribute("shown",this.shown?"true":"false");i===null||i===void 0?void 0:i.setAttribute("index",String(s));i===null||i===void 0?void 0:i.setAttribute("dropdown-id",this.dropdownId);i===null||i===void 0?void 0:i.setAttribute("dropdownid",this.dropdownId)}componentDidLoad(){var i;(i=this.slotEls)===null||i===void 0?void 0:i.forEach(((i,s)=>{if(i.tagName==="BS-DROPDOWN-OPTION"){this.passDownProps(i,s);const t=i===null||i===void 0?void 0:i.getAttribute("selected");if(t!==null){this.selectedIndex=s}}}))}componentDidUpdate(){var i;if(this.shown){this._slotEls=undefined}(i=this.slotEls)===null||i===void 0?void 0:i.forEach(((i,s)=>{if(i.tagName==="BS-DROPDOWN-OPTION"){this.passDownProps(i,s);if(this.selectedIndex===s){i.setAttribute("selected","true")}else{i.removeAttribute("selected")}}}))}removeCurrentFocus(){if(this.focusedIndex>-1){this.slotEls[this.focusedIndex].removeAttribute("focused")}}handleKeyDown(i){if(this.shown){switch(i.key){case"ArrowDown":this.traverse("down");i.preventDefault();break;case"ArrowUp":this.traverse("up");i.preventDefault();break;case"Home":this.traverse("home");i.preventDefault();break;case"End":this.traverse("end");i.preventDefault();break;case"Tab":i.preventDefault();break;case"Escape":this.closeOptions();i.preventDefault();break}}}traverse(i){let s;switch(i){case"up":s=this.focusedIndex-1<0?this.slotEls.length-1:this.focusedIndex-1;break;case"down":s=(this.focusedIndex+1)%this.slotEls.length;break;case"home":s=0;break;case"end":s=this.slotEls.length-1;break}this.removeCurrentFocus();this.slotEls[s].setAttribute("focused","true");this.focusedIndex=s}closeOptions(){this.removeCurrentFocus();this.close.emit()}handleMouseFocus(i){if(this.shown){this.removeCurrentFocus();this.focusedIndex=i.detail}}handleClickOutside(i){if(this.shown){if(!this.hostEl.contains(i.target)){this.closeOptions()}}}handleSelect(i){this.activeDescendantId=i.detail.id;this.selectedIndex=i.detail.index;this.dropdownchange.emit(i.detail.value);this.closeOptions()}clearTimers(){if(this.shownTimer){clearTimeout(this.shownTimer);this.shownTimer=undefined}if(this.animationTimer){clearTimeout(this.animationTimer);this.animationTimer=undefined}}handleShown(i){this.clearTimers();if(i){this.toggleEl=document.activeElement;this.shownTimer=setTimeout((()=>this.hostEl.setAttribute("data-shown","")),10);if(this.selectedIndex>-1){this.animationTimer=setTimeout((()=>{this.focusedIndex=this.selectedIndex;this.slotEls[this.focusedIndex].setAttribute("focused","true")}),this.animationDuration*2)}}else{this.removeCurrentFocus();if(this.toggleEl){this.toggleEl.focus()}this.focusedIndex=-1;this.shownTimer=setTimeout((()=>this.hostEl.removeAttribute("data-shown")),this.animationDuration)}}render(){return t(e,{"data-position":this.position||undefined,"data-variant":this.variant||undefined},t("ul",{id:this.dropdownId,role:"listbox","aria-label":this.label||undefined,"aria-activedescendant":this.activeDescendantId||undefined,part:"options",ref:i=>this.optionsEl=i},t("slot",null)))}get hostEl(){return h(this)}static get watchers(){return{shown:["handleShown"]}}};export{d as bs_dropdown_options};
//# sourceMappingURL=p-74fa340b.entry.js.map