import{r as t,c as i,h as s,g as e}from"./p-65ddb289.js";class h{constructor(s){t(this,s),this.value=[],this.change=i(this,"change",7)}componentWillLoad(){this.value||(this.value=[]),this.computeMultiList()}componentWillUpdate(){this.value||(this.value=[]),this.computeMultiList()}computeMultiList(){const t=this.maxElementsColumn?this.options.size/this.maxElementsColumn+this.options.size%this.maxElementsColumn:0;if(t>0){this.multiList=new Map;const i=Array.from(this.options.keys());for(let s=0;s<t;s++){const t=(s+1)*this.maxElementsColumn;this.multiList.set(s,i.slice(s*this.maxElementsColumn,t<this.options.size?t:this.options.size))}}else this.multiList=(new Map).set(0,Array.from(this.options.keys()))}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,i){t.stopPropagation(),t.preventDefault(),t.detail?this.value.push(i):this.value.splice(this.value.indexOf(i),1)}render(){return[s("materials-text-field",{focused:!!this.value&&this.value.length>0,readonly:!0,label:this.label,overflow:!0,"trailing-icon":this.trailingIcon,dense:this.dense,ref:t=>this.multiSelectInput=t,onClick:t=>this.openMultiSelectDialog(t)}),s("materials-dialog",{acceptButton:"Sélectionner",cancelButton:"Annuler","close-button":!0,onAccept:()=>this.fillMultiSelectInput(),ref:t=>this.multiSelectDialog=t},s("div",{slot:"body",class:"body-list"},this.multiList&&Array.from(this.multiList.keys()).map(t=>s("materials-list",null,this.multiList.get(t).map(t=>s("materials-list-item-checkbox",{onChange:i=>this.toggleOption(i,t),checked:this.value&&this.value.length>0&&!!this.value.find(i=>t===i),label:this.options.get(t),value:t}))))))]}get host(){return e(this)}static get style(){return":host{display:block;font-size:1rem}:host materials-text-field{text-overflow:ellipsis}:host .body-list{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row}"}}export{h as materials_multiple_select};