import{r as t,c as s,h as i,H as h,g as e}from"./p-561c15f0.js";const o=class{constructor(i){t(this,i),this.balChange=s(this,"balChange",7),this.balInput=s(this,"balInput",7),this.balCancel=s(this,"balCancel",7),this.balBlur=s(this,"balBlur",7),this.balFocus=s(this,"balFocus",7),this.balClick=s(this,"balClick",7),this.balKeyPress=s(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.options=[]}optionsChanged(){this.typeahead&&this.remote&&(0===this.options.length?this.dropdownElement.close():this.inputElement.value.length>0&&this.dropdownElement.open())}async open(){this.disabled||this.dropdownElement.open()}async close(){this.disabled||this.dropdownElement.close()}async select(t){var s,i;this.value=t,this.balChange.emit(this.value),this.inputElement.value=null===(s=this.value)||void 0===s?void 0:s.text,await(null===(i=this.dropdownElement)||void 0===i?void 0:i.toggle()),this.updateOptionProps()}async clear(){this.value=null,this.inputElement.value="",this.updateOptionProps()}async setFocus(){this.inputElement&&this.inputElement.focus()}async onInputClick(t){var s;this.disabled||(this.balClick.emit(t),this.typeahead||await(null===(s=this.dropdownElement)||void 0===s?void 0:s.toggle()))}onDropdownChange(t){this.isDropdownOpen=t.detail,t.stopPropagation()}onInput(t){const s=t.target.value;this.balInput.emit(s),this.remote||this.updateOptionProps(),this.typeahead&&0===s.length&&this.dropdownElement.close(),this.typeahead&&!this.remote&&s.length>0&&this.dropdownElement.open()}updateOptionProps(){const t=this.inputElement.value;this.childOptions.forEach(s=>{if(!this.remote&&this.typeahead){const i=this.compareForFilter(""+s.value.text||"",""+t);s.setAttribute("hidden",""+!i)}s.setAttribute("selected",""+(!!this.value&&this.value.value===s.value.value))})}compareForFilter(t,s){return t=t.toLocaleLowerCase(),s=s.toLocaleLowerCase(),t.indexOf(s)>=0}onKeyPress(t){this.balKeyPress.emit(t),this.typeahead||(this.textToScrollTo=this.textToScrollTo+t.key,clearTimeout(this.clearScrollToValue),this.clearScrollToValue=setTimeout(()=>{this.scrollToText(this.textToScrollTo),this.textToScrollTo=""},600))}async scrollToText(t){const s=await this.dropdownElement.getContentElement(),i=this.childOptions.find(s=>this.compareForFilter(s.value.text,t));i&&(s.scrollTop=i.offsetTop)}get childOptions(){return Array.from(this.element.querySelectorAll("bal-select-option"))}render(){var t;return i(h,{role:"listbox"},i("bal-dropdown",{expanded:this.expanded,scrollable:this.scrollable,onBalCollapse:t=>this.onDropdownChange(t),ref:t=>this.dropdownElement=t},i("div",{class:"control has-icons-right",slot:"trigger"},i("input",{class:{input:!0,clickable:!0,"is-inverted":this.inverted},readonly:!this.typeahead||this.loading,autoComplete:"off",disabled:this.disabled,placeholder:this.placeholder,value:null===(t=this.value)||void 0===t?void 0:t.text,onInput:t=>this.onInput(t),onClick:t=>this.onInputClick(t),onKeyPress:t=>this.onKeyPress(t),onBlur:t=>this.balBlur.emit(t),onFocus:t=>this.balFocus.emit(t),ref:t=>this.inputElement=t}),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"})),this.options.map(t=>i("bal-select-option",{value:t}))))}get element(){return e(this)}static get watchers(){return{options:["optionsChanged"]}}};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}