import{r as s,c as t,h as i,H as h,g as e}from"./p-280c4990.js";const o=class{constructor(i){s(this,i),this.balChange=t(this,"balChange",7),this.balInput=t(this,"balInput",7),this.balBlur=t(this,"balBlur",7),this.balFocus=t(this,"balFocus",7),this.balClick=t(this,"balClick",7),this.balKeyPress=t(this,"balKeyPress",7),this.isDropdownOpen=!1,this.textToScrollTo="",this.remote=!1,this.expanded=!1,this.inverted=!1,this.disabled=!1,this.typeahead=!1,this.loading=!1,this.placeholder="",this.scrollable=250,this.value=""}async open(){this.disabled||this.dropdownElement.open()}async close(){this.disabled||this.dropdownElement.close()}async select(s){var t;this.value=s.value,this.balChange.emit(this.value),this.inputElement.value=null==s?void 0:s.label,await(null===(t=this.dropdownElement)||void 0===t?void 0:t.toggle()),this.updateOptionProps()}async clear(){this.value="",this.inputElement.value="",this.updateOptionProps()}async setFocus(){this.inputElement&&this.inputElement.focus()}async sync(){this.updateOptionProps()}async onInputClick(s){var t;this.disabled||(this.balClick.emit(s),this.typeahead||await(null===(t=this.dropdownElement)||void 0===t?void 0:t.toggle()))}onDropdownChange(s){this.isDropdownOpen=s.detail,s.stopPropagation()}onInput(s){const t=s.target.value;this.value="",this.balChange.emit(this.value),this.balInput.emit(t),this.updateOptionProps(),this.typeahead&&0===t.length&&this.dropdownElement.close(),this.typeahead&&t.length>0&&this.dropdownElement.open()}updateOptionProps(){const s=this.inputElement.value;this.childOptions.forEach(t=>{if(!this.remote&&this.typeahead){const i=this.compareForFilter(""+t.label||"",""+s);t.setAttribute("hidden",""+!i)}t.setAttribute("selected",""+(!!this.value&&this.value===t.value))})}compareForFilter(s,t){return s=s.toLocaleLowerCase(),t=t.toLocaleLowerCase(),s.indexOf(t)>=0}onKeyPress(s){this.balKeyPress.emit(s),this.typeahead||(this.textToScrollTo=this.textToScrollTo+s.key,clearTimeout(this.clearScrollToValue),this.clearScrollToValue=setTimeout(()=>{this.scrollToText(this.textToScrollTo),this.textToScrollTo=""},600))}async scrollToText(s){const t=await this.dropdownElement.getContentElement(),i=this.childOptions.find(t=>this.compareForFilter(t.label,s));i&&(t.scrollTop=i.offsetTop)}get childOptions(){return Array.from(this.element.querySelectorAll("bal-select-option"))}render(){return i(h,{role:"listbox"},i("bal-dropdown",{expanded:this.expanded,scrollable:this.scrollable,onBalCollapse:s=>this.onDropdownChange(s),ref:s=>this.dropdownElement=s},i("div",{class:"control has-icons-right",slot:"trigger"},i("input",{class:{input:!0,clickable:!0,"is-inverted":this.inverted},readonly:!this.typeahead,autoComplete:"off",disabled:this.disabled,placeholder:this.placeholder,onInput:s=>this.onInput(s),onClick:s=>this.onInputClick(s),onKeyPress:s=>this.onKeyPress(s),onBlur:s=>this.balBlur.emit(s),onFocus:s=>this.balFocus.emit(s),ref:s=>this.inputElement=s}),i("bal-icon",{size:"medium","is-right":!0,turn:!this.loading&&!this.typeahead&&this.isDropdownOpen,rotate:this.loading,color:this.inverted?"white":"blue",name:this.loading?"refresh":this.typeahead?"search":"caret-down"})),i("slot",null)))}get element(){return e(this)}};o.style="@keyframes spinAround{from{transform:rotate(0deg)}to{transform:rotate(359deg)}}@keyframes spinAround{from{transform:rotate(0deg)}to{transform:rotate(359deg)}}.sc-bal-select-h{display:block}.sc-bal-select-h{display:block}.is-turned-up.sc-bal-select{rotate:180deg}";export{o as bal_select}