import{forwardRef,EventEmitter,Component,ChangeDetectionStrategy,ViewEncapsulation,ElementRef,ChangeDetectorRef,Input,Output,ViewChild,ContentChild,ContentChildren,NgModule}from"@angular/core";import{CommonModule}from"@angular/common";import{FilterService,Header,Footer,PrimeTemplate,SharedModule}from"primeng/api";import{DomHandler}from"primeng/dom";import{ObjectUtils}from"primeng/utils";import{NG_VALUE_ACCESSOR}from"@angular/forms";import{RippleModule}from"primeng/ripple";const LISTBOX_VALUE_ACCESSOR={provide:NG_VALUE_ACCESSOR,useExisting:forwardRef(()=>Listbox),multi:!0};class Listbox{constructor(e,t,i){this.el=e,this.cd=t,this.filterService=i,this.checkbox=!1,this.filter=!1,this.filterMatchMode="contains",this.metaKeySelection=!0,this.showToggleAll=!0,this.onChange=new EventEmitter,this.onClick=new EventEmitter,this.onDblClick=new EventEmitter,this.onModelChange=(()=>{}),this.onModelTouched=(()=>{})}get options(){return this._options}set options(e){this._options=e}get filterValue(){return this._filterValue}set filterValue(e){this._filterValue=e,this.activateFilter()}ngAfterContentInit(){this.templates.forEach(e=>{switch(e.getType()){case"item":this.itemTemplate=e.template;break;case"group":this.groupTemplate=e.template;break;case"header":this.headerTemplate=e.template;break;case"footer":this.footerTemplate=e.template;break;default:this.itemTemplate=e.template}})}getOptionLabel(e){return this.optionLabel?ObjectUtils.resolveFieldData(e,this.optionLabel):null!=e.label?e.label:e}getOptionGroupChildren(e){return this.optionGroupChildren?ObjectUtils.resolveFieldData(e,this.optionGroupChildren):e.items}getOptionGroupLabel(e){return this.optionGroupLabel?ObjectUtils.resolveFieldData(e,this.optionGroupLabel):null!=e.label?e.label:e}getOptionValue(e){return this.optionValue?ObjectUtils.resolveFieldData(e,this.optionValue):this.optionLabel?e:e.value}isOptionDisabled(e){return this.optionDisabled?ObjectUtils.resolveFieldData(e,this.optionDisabled):void 0!==e.disabled&&e.disabled}writeValue(e){this.value=e,this.cd.markForCheck()}registerOnChange(e){this.onModelChange=e}registerOnTouched(e){this.onModelTouched=e}setDisabledState(e){this.disabled=e,this.cd.markForCheck()}onOptionClick(e,t){this.disabled||this.isOptionDisabled(t)||this.readonly||(this.multiple?this.checkbox?this.onOptionClickCheckbox(e,t):this.onOptionClickMultiple(e,t):this.onOptionClickSingle(e,t),this.onClick.emit({originalEvent:e,option:t,value:this.value}),this.optionTouched=!1)}onOptionTouchEnd(e){this.disabled||this.isOptionDisabled(e)||this.readonly||(this.optionTouched=!0)}onOptionDoubleClick(e,t){this.disabled||this.isOptionDisabled(t)||this.readonly||this.onDblClick.emit({originalEvent:e,option:t,value:this.value})}onOptionClickSingle(e,t){let i=this.isSelected(t),l=!1;if(!this.optionTouched&&this.metaKeySelection){let o=e.metaKey||e.ctrlKey;i?o&&(this.value=null,l=!0):(this.value=this.getOptionValue(t),l=!0)}else this.value=i?null:this.getOptionValue(t),l=!0;l&&(this.onModelChange(this.value),this.onChange.emit({originalEvent:e,value:this.value}))}onOptionClickMultiple(e,t){let i=this.isSelected(t),l=!1;if(!this.optionTouched&&this.metaKeySelection){let o=e.metaKey||e.ctrlKey;i?(o?this.removeOption(t):this.value=[this.getOptionValue(t)],l=!0):(this.value=o&&this.value||[],this.value=[...this.value,this.getOptionValue(t)],l=!0)}else i?this.removeOption(t):this.value=[...this.value||[],this.getOptionValue(t)],l=!0;l&&(this.onModelChange(this.value),this.onChange.emit({originalEvent:e,value:this.value}))}onOptionClickCheckbox(e,t){if(this.disabled||this.readonly)return;this.isSelected(t)?this.removeOption(t):(this.value=this.value?this.value:[],this.value=[...this.value,this.getOptionValue(t)]),this.onModelChange(this.value),this.onChange.emit({originalEvent:e,value:this.value})}removeOption(e){this.value=this.value.filter(t=>!ObjectUtils.equals(t,this.getOptionValue(e),this.dataKey))}isSelected(e){let t=!1,i=this.getOptionValue(e);if(this.multiple){if(this.value)for(let e of this.value)if(ObjectUtils.equals(e,i,this.dataKey)){t=!0;break}}else t=ObjectUtils.equals(this.value,i,this.dataKey);return t}get allChecked(){let e=this.optionsToRender;if(e&&0!==e.length){let t=0,i=0,l=0,o=this.group?0:this.optionsToRender.length;for(let n of e)if(this.group){if(n.items)for(let e of n.items){let n=this.isOptionDisabled(e),s=this.isSelected(e);if(n)s?t++:i++;else{if(!s)return!1;l++}o++}}else{let e=this.isOptionDisabled(n),o=this.isSelected(n);if(e)o?t++:i++;else{if(!o)return!1;l++}}return o===t||o===l||l&&o===l+i+t}return!1}get optionsToRender(){return this._filteredOptions||this.options}hasFilter(){return this._filterValue&&this._filterValue.trim().length>0}onFilter(e){this._filterValue=e.target.value,this.activateFilter()}activateFilter(){if(this.hasFilter()&&this._options)if(this.group){let e=(this.optionLabel||"label").split(","),t=[];for(let i of this.options){let l=this.filterService.filter(this.getOptionGroupChildren(i),e,this.filterValue,this.filterMatchMode,this.filterLocale);l&&l.length&&t.push({label:i.label,value:i.value,items:l})}this._filteredOptions=t}else this._filteredOptions=this._options.filter(e=>this.filterService.filters[this.filterMatchMode](this.getOptionLabel(e),this._filterValue,this.filterLocale));else this._filteredOptions=null}get toggleAllDisabled(){let e=this.optionsToRender;if(e&&0!==e.length){for(let t of e)if(!this.isOptionDisabled(t))return!1;return!0}return!0}toggleAll(e){if(this.disabled||this.toggleAllDisabled||this.readonly)return;this.allChecked?this.uncheckAll():this.checkAll(),this.onModelChange(this.value),this.onChange.emit({originalEvent:e,value:this.value}),e.preventDefault()}checkAll(){let e=this.optionsToRender,t=[];e.forEach(e=>{if(this.group)e.items&&e.items.forEach(e=>{let i=this.isOptionDisabled(e);(!i||i&&this.isSelected(e))&&t.push(this.getOptionValue(e))});else{let i=this.isOptionDisabled(e);(!i||i&&this.isSelected(e))&&t.push(this.getOptionValue(e))}}),this.value=t}uncheckAll(){let e=this.optionsToRender,t=[];e.forEach(e=>{if(this.group)e.items&&e.items.forEach(e=>{this.isOptionDisabled(e)&&this.isSelected(e)&&t.push(this.getOptionValue(e))});else{this.isOptionDisabled(e)&&this.isSelected(e)&&t.push(this.getOptionValue(e))}}),this.value=t}onOptionKeyDown(e,t){if(this.readonly)return;let i=e.currentTarget;switch(e.which){case 40:var l=this.findNextItem(i);l&&l.focus(),e.preventDefault();break;case 38:var o=this.findPrevItem(i);o&&o.focus(),e.preventDefault();break;case 13:this.onOptionClick(e,t),e.preventDefault()}}findNextItem(e){let t=e.nextElementSibling;return t?DomHandler.hasClass(t,"p-disabled")||DomHandler.isHidden(t)||DomHandler.hasClass(t,"p-listbox-item-group")?this.findNextItem(t):t:null}findPrevItem(e){let t=e.previousElementSibling;return t?DomHandler.hasClass(t,"p-disabled")||DomHandler.isHidden(t)||DomHandler.hasClass(t,"p-listbox-item-group")?this.findPrevItem(t):t:null}onHeaderCheckboxFocus(){this.headerCheckboxFocus=!0}onHeaderCheckboxBlur(){this.headerCheckboxFocus=!1}}Listbox.decorators=[{type:Component,args:[{selector:"p-listbox",template:'\n