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.balBlur=s(this,"balBlur",7),this.balFocus=s(this,"balFocus",7),this.balClick=s(this,"balClick",7),this.balKeyDown=s(this,"balKeyDown",7),this.balKeyPress=s(this,"balKeyPress",7),this.balKeyUp=s(this,"balKeyUp",7),this.optionElements=new Map,this.textToScrollTo="",this.label="",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(){0===this.options.length&&this.dropdownElement.close()}async optionSelect(t){var s,i;t.preventDefault(),t.stopPropagation(),this.value=Object.assign({},t.detail),this.balChange.emit(t.detail),await(null===(s=this.dropdownElement)||void 0===s?void 0:s.toggle()),this.dispatchEventToOptions(this.buildCustomEvent("balSelectChanged",this.value)),this.inputElement.value=null===(i=this.value)||void 0===i?void 0:i.text}async clear(){this.value=null,this.inputElement.value="",this.dispatchEventToOptions(this.buildCustomEvent("balSelectChanged",this.value))}async onInputClick(t){var s;this.balClick.emit(t),this.typeahead||await(null===(s=this.dropdownElement)||void 0===s?void 0:s.toggle())}onInput(t){const s=t.target.value;this.balInput.emit(s),this.remote||this.dispatchEventToOptions(this.buildCustomEvent("balSelectInput",s)),this.options.length>0&&this.dropdownElement.open()}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))}render(){var t;return this.optionElements.clear(),i(h,null,i("bal-dropdown",{expanded:this.expanded,scrollable:this.scrollable,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,disabled:this.disabled,placeholder:this.placeholder,autoComplete:"off",value:null===(t=this.value)||void 0===t?void 0:t.text,onInput:t=>this.onInput(t),onBlur:t=>this.balBlur.emit(t),onClick:t=>this.onInputClick(t),onKeyDown:t=>this.balKeyDown.emit(t),onKeyPress:t=>this.onKeyPress(t),onKeyUp:t=>this.balKeyUp.emit(t),onFocus:t=>this.balFocus.emit(t),ref:t=>this.inputElement=t}),i("bal-icon",{size:"medium",rotate:this.loading,color:this.inverted?"white":"blue",name:this.loading?"refresh":this.typeahead?"search":"caret-down","is-right":!0})),this.options.map(t=>i("bal-select-option",{ref:s=>this.optionElements.set(t.value,s),value:t}))))}async scrollToText(t){const s=await this.dropdownElement.getContentElement(),i=this.options.find(s=>s.text.startsWith(t)),h=this.optionElements.get(i.value);s.scrollTop=h.offsetTop}dispatchEventToOptions(t){this.element.querySelectorAll("bal-select-option").forEach(s=>s.dispatchEvent(t))}buildCustomEvent(t,s){return new CustomEvent(t,{detail:s})}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}";export{o as bal_select}