import{r as e,c as t,h as s}from"./p-fb8320e0.js";class l{constructor(s){e(this,s),this.dense=!1,this.change=t(this,"change",7)}componentDidLoad(){this.watchValue()}componentWillLoad(){this.watchValue()}watchValue(){this.value?this.value.label=this.value.label?this.value.label:this.value.value:this.value={value:null,label:null}}selectSuggestion(e){if(this.menuElement.close(),this.suggestions){const t={value:e,label:this.suggestions.get(e)};this.value=Object.assign({},t)}this.change.emit(this.value)}execAutocomplete(e){this.value.label=e.target.value,this.autocomplete(e.target.value).then(e=>this.suggestions=e),this.menuElement.open()}emptyField(){this.textElement.value||(this.value=null,this.change.emit(this.value))}render(){return[s("materials-text-field",{"trailing-icon":this.trailingIcon,dense:this.dense,label:this.label,value:this.value.label,onInput:e=>this.execAutocomplete(e),onChange:e=>{e.stopPropagation(),e.preventDefault(),this.change.emit()}}),s("materials-menu",{ref:e=>this.menuElement=e},this.suggestions?Array.from(this.suggestions.keys()).map(e=>s("materials-list-item",{onClick:()=>this.selectSuggestion(e)},this.suggestions.get(e))):null)]}static get watchers(){return{value:["watchValue"]}}static get style(){return":host{display:block}"}}export{l as materials_autocomplete};