import{r as t,c as e,h as i,g as l}from"./p-b31dd0cc.js";class a{constructor(i){t(this,i),this.value=[],this.change=e(this,"change",7)}componentWillLoad(){this.value||(this.value=[])}componentWillUpdate(){this.value||(this.value=[])}componentDidLoad(){this.displayValue()}componentDidUpdate(){this.displayValue()}openMultiSelectDialog(t){t.stopPropagation(),t.preventDefault(),this.multiSelectDialog.dialogTitle=this.dialogTitle,this.multiSelectDialog.toggle()}fillMultiSelectInput(){this.displayValue(),this.change.emit()}displayValue(){if(this.value){const t=this.value.map(t=>this.options.get(t)).join(", ");this.multiSelectInput.componentOnReady().then(()=>{this.multiSelectInput.value=t,this.multiSelectInput.title=t})}}toggleOption(t,e){t.stopPropagation(),t.preventDefault(),t.detail?this.value.push(e):this.value.splice(this.value.indexOf(e),1)}render(){return[i("materials-text-field",{disabled:!0,label:this.label,overflow:!0,"trailing-icon":"search",ref:t=>this.multiSelectInput=t,onClick:t=>this.openMultiSelectDialog(t)}),i("materials-dialog",{acceptButton:"Sélectionner",cancelButton:"Annuler","close-button":!0,onAccept:()=>this.fillMultiSelectInput(),ref:t=>this.multiSelectDialog=t},i("materials-list",{slot:"body"},this.options&&Array.from(this.options.keys()).map(t=>i("materials-list-item-checkbox",{onChange:e=>this.toggleOption(e,t),checked:this.value&&this.value.length>0&&!!this.value.find(e=>t===e),label:this.options.get(t),value:t}))))]}get host(){return l(this)}static get style(){return":host{display:block;cursor:pointer}materials-text-field{text-overflow:ellipsis}"}}export{a as materials_multiple_select};