import{forwardRef,EventEmitter,Component,ViewEncapsulation,Input,Output,ChangeDetectionStrategy,ElementRef,Renderer2,ChangeDetectorRef,ViewChild,ContentChild,ContentChildren,NgModule}from"@angular/core";import{trigger,transition,style,animate}from"@angular/animations";import{CommonModule}from"@angular/common";import{DomHandler,ConnectedOverlayScrollHandler}from"primeng/dom";import{ObjectUtils}from"primeng/utils";import{FilterService,Footer,Header,PrimeTemplate,SharedModule}from"primeng/api";import{NG_VALUE_ACCESSOR}from"@angular/forms";import{ScrollingModule}from"@angular/cdk/scrolling";import{TooltipModule}from"primeng/tooltip";import{RippleModule}from"primeng/ripple";const MULTISELECT_VALUE_ACCESSOR={provide:NG_VALUE_ACCESSOR,useExisting:forwardRef(()=>MultiSelect),multi:!0};class MultiSelectItem{constructor(){this.onClick=new EventEmitter,this.onKeydown=new EventEmitter}onOptionClick(e){this.onClick.emit({originalEvent:e,option:this.option})}onOptionKeydown(e){this.onKeydown.emit({originalEvent:e,option:this.option})}}MultiSelectItem.decorators=[{type:Component,args:[{selector:"p-multiSelectItem",template:'\n
\n \n {{label}}\n \n \n ',encapsulation:ViewEncapsulation.None}]}],MultiSelectItem.propDecorators={option:[{type:Input}],selected:[{type:Input}],label:[{type:Input}],disabled:[{type:Input}],itemSize:[{type:Input}],template:[{type:Input}],onClick:[{type:Output}],onKeydown:[{type:Output}]};class MultiSelect{constructor(e,t,i,l){this.el=e,this.renderer=t,this.cd=i,this.filterService=l,this.filter=!0,this.displaySelectedLabel=!0,this.maxSelectedLabels=3,this.selectedItemsLabel="{0} items selected",this.showToggleAll=!0,this.emptyFilterMessage="No results found",this.resetFilterOnHide=!1,this.dropdownIcon="pi pi-chevron-down",this.showHeader=!0,this.autoZIndex=!0,this.baseZIndex=0,this.showTransitionOptions=".12s cubic-bezier(0, 0, 0.2, 1)",this.hideTransitionOptions=".1s linear",this.filterMatchMode="contains",this.tooltip="",this.tooltipPosition="right",this.tooltipPositionStyle="absolute",this.autofocusFilter=!0,this.display="comma",this.onChange=new EventEmitter,this.onFocus=new EventEmitter,this.onBlur=new EventEmitter,this.onClick=new EventEmitter,this.onPanelShow=new EventEmitter,this.onPanelHide=new EventEmitter,this.scrollHeight="200px",this.onModelChange=(()=>{}),this.onModelTouched=(()=>{})}set defaultLabel(e){this._defaultLabel=e,this.updateLabel()}get defaultLabel(){return this._defaultLabel}set placeholder(e){this._placeholder=e,this.updateLabel()}get placeholder(){return this._placeholder}get options(){return this._options}set options(e){this._options=e}get filterValue(){return this._filterValue}set filterValue(e){this._filterValue=e,this.activateFilter()}ngOnInit(){this.updateLabel()}ngAfterContentInit(){this.templates.forEach(e=>{switch(e.getType()){case"item":this.itemTemplate=e.template;break;case"group":this.groupTemplate=e.template;break;case"selectedItems":this.selectedItemsTemplate=e.template;break;case"header":this.headerTemplate=e.template;break;case"footer":this.footerTemplate=e.template;break;default:this.itemTemplate=e.template}})}ngAfterViewInit(){this.overlayVisible&&this.show()}ngAfterViewChecked(){this.filtered&&(this.alignOverlay(),this.filtered=!1)}getOptionLabel(e){return this.optionLabel?ObjectUtils.resolveFieldData(e,this.optionLabel):null!=e.label?e.label:e}getOptionValue(e){return this.optionValue?ObjectUtils.resolveFieldData(e,this.optionValue):this.optionLabel?e:e.value}getOptionGroupLabel(e){return this.optionGroupLabel?ObjectUtils.resolveFieldData(e,this.optionGroupLabel):null!=e.label?e.label:e}getOptionGroupChildren(e){return this.optionGroupChildren?ObjectUtils.resolveFieldData(e,this.optionGroupChildren):e.items}isOptionDisabled(e){return(this.optionDisabled?ObjectUtils.resolveFieldData(e,this.optionDisabled):void 0!==e.disabled&&e.disabled)||this.maxSelectionLimitReached&&!this.isSelected(e)}writeValue(e){this.value=e,this.updateLabel(),this.updateFilledState(),this.checkSelectionLimit(),this.cd.markForCheck()}checkSelectionLimit(){this.selectionLimit&&this.value&&this.value.length===this.selectionLimit?this.maxSelectionLimitReached=!0:this.maxSelectionLimitReached=!1}updateFilledState(){this.filled=this.value&&this.value.length>0}registerOnChange(e){this.onModelChange=e}registerOnTouched(e){this.onModelTouched=e}setDisabledState(e){this.disabled=e,this.cd.markForCheck()}onOptionClick(e){let t=e.option;if(this.isOptionDisabled(t))return;let i=this.getOptionValue(t),l=this.findSelectionIndex(i);-1!=l?(this.value=this.value.filter((e,t)=>t!=l),this.selectionLimit&&(this.maxSelectionLimitReached=!1)):((!this.selectionLimit||!this.value||this.value.length{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}show(){this.overlayVisible||(this.overlayVisible=!0)}onOverlayAnimationStart(e){switch(e.toState){case"visible":this.overlay=e.element,this.appendOverlay(),this.autoZIndex&&(this.overlay.style.zIndex=String(this.baseZIndex+ ++DomHandler.zindex)),this.alignOverlay(),this.bindDocumentClickListener(),this.bindDocumentResizeListener(),this.bindScrollListener(),this.filterInputChild&&this.filterInputChild.nativeElement&&(this.preventModelTouched=!0,this.autofocusFilter&&this.filterInputChild.nativeElement.focus()),this.onPanelShow.emit();break;case"void":this.onOverlayHide()}}appendOverlay(){this.appendTo&&("body"===this.appendTo?document.body.appendChild(this.overlay):DomHandler.appendChild(this.overlay,this.appendTo),this.overlay.style.minWidth||(this.overlay.style.minWidth=DomHandler.getWidth(this.containerViewChild.nativeElement)+"px"))}restoreOverlayAppend(){this.overlay&&this.appendTo&&this.el.nativeElement.appendChild(this.overlay)}alignOverlay(){this.overlay&&(this.appendTo?DomHandler.absolutePosition(this.overlay,this.containerViewChild.nativeElement):DomHandler.relativePosition(this.overlay,this.containerViewChild.nativeElement))}hide(){this.overlayVisible=!1,this.unbindDocumentClickListener(),this.resetFilterOnHide&&(this.filterInputChild.nativeElement.value="",this._filterValue=null,this._filteredOptions=null),this.onPanelHide.emit(),this.cd.markForCheck()}close(e){this.hide(),e.preventDefault(),e.stopPropagation()}onMouseclick(e,t){this.disabled||this.readonly||e.target.isSameNode(this.accessibleViewChild.nativeElement)||(this.onClick.emit(e),this.isOverlayClick(e)||DomHandler.hasClass(e.target,"p-multiselect-token-icon")||(this.overlayVisible?this.hide():(t.focus(),this.show())))}removeChip(e,t){this.value=this.value.filter(t=>!ObjectUtils.equals(t,e,this.dataKey)),this.onModelChange(this.value),this.onChange.emit({originalEvent:t,value:this.value}),this.updateLabel(),this.updateFilledState()}isOverlayClick(e){let t=e.target;return!!this.overlay&&(this.overlay.isSameNode(t)||this.overlay.contains(t))}isOutsideClicked(e){return!(this.el.nativeElement.isSameNode(e.target)||this.el.nativeElement.contains(e.target)||this.isOverlayClick(e))}onInputFocus(e){this.focus=!0,this.onFocus.emit({originalEvent:e})}onInputBlur(e){this.focus=!1,this.onBlur.emit({originalEvent:e}),this.preventModelTouched||this.onModelTouched(),this.preventModelTouched=!1}onOptionKeydown(e){if(!this.readonly)switch(e.originalEvent.which){case 40:var t=this.findNextItem(e.originalEvent.target.parentElement);t&&t.focus(),e.originalEvent.preventDefault();break;case 38:var i=this.findPrevItem(e.originalEvent.target.parentElement);i&&i.focus(),e.originalEvent.preventDefault();break;case 13:this.onOptionClick(e),e.originalEvent.preventDefault()}}findNextItem(e){let t=e.nextElementSibling;return t?DomHandler.hasClass(t.children[0],"p-disabled")||DomHandler.isHidden(t.children[0])||DomHandler.hasClass(t,"p-multiselect-item-group")?this.findNextItem(t):t.children[0]:null}findPrevItem(e){let t=e.previousElementSibling;return t?DomHandler.hasClass(t.children[0],"p-disabled")||DomHandler.isHidden(t.children[0])||DomHandler.hasClass(t,"p-multiselect-item-group")?this.findPrevItem(t):t.children[0]:null}onKeydown(e){switch(e.which){case 40:!this.overlayVisible&&e.altKey&&(this.show(),e.preventDefault());break;case 32:this.overlayVisible||(this.show(),e.preventDefault());break;case 27:this.hide()}}updateLabel(){if(this.value&&this.options&&this.value.length&&this.displaySelectedLabel){let e="";for(let t=0;t0&&(e+=", "),e+=i)}if(this.value.length<=this.maxSelectedLabels)this.valuesAsString=e;else{let e=/{(.*?)}/;e.test(this.selectedItemsLabel)?this.valuesAsString=this.selectedItemsLabel.replace(this.selectedItemsLabel.match(e)[0],this.value.length+""):this.valuesAsString=this.selectedItemsLabel}}else this.valuesAsString=this.placeholder||this.defaultLabel}findLabelByValue(e){if(this.group){let t=null;for(let i=0;i0}onFilter(e){this._filterValue=e.target.value,this.activateFilter()}activateFilter(){if(this.hasFilter()&&this._options){let e=(this.filterBy||this.optionLabel||"label").split(",");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.filterService.filter(this.options,e,this._filterValue,this.filterMatchMode,this.filterLocale)}else this._filteredOptions=null}onHeaderCheckboxFocus(){this.headerCheckboxFocus=!0}onHeaderCheckboxBlur(){this.headerCheckboxFocus=!1}bindDocumentClickListener(){if(!this.documentClickListener){const e=this.el?this.el.nativeElement.ownerDocument:"document";this.documentClickListener=this.renderer.listen(e,"click",e=>{this.isOutsideClicked(e)&&this.hide()})}}unbindDocumentClickListener(){this.documentClickListener&&(this.documentClickListener(),this.documentClickListener=null)}bindDocumentResizeListener(){this.documentResizeListener=this.onWindowResize.bind(this),window.addEventListener("resize",this.documentResizeListener)}unbindDocumentResizeListener(){this.documentResizeListener&&(window.removeEventListener("resize",this.documentResizeListener),this.documentResizeListener=null)}onWindowResize(){DomHandler.isAndroid()||this.hide()}bindScrollListener(){this.scrollHandler||(this.scrollHandler=new ConnectedOverlayScrollHandler(this.containerViewChild.nativeElement,()=>{this.overlayVisible&&this.hide()})),this.scrollHandler.bindScrollListener()}unbindScrollListener(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}onOverlayHide(){this.unbindDocumentClickListener(),this.unbindDocumentResizeListener(),this.unbindScrollListener(),this.overlay=null,this.onModelTouched()}ngOnDestroy(){this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.restoreOverlayAppend(),this.onOverlayHide()}}MultiSelect.decorators=[{type:Component,args:[{selector:"p-multiSelect",template:'\n \n
\n \n
\n
\n
\n
\n {{valuesAsString || \'empty\'}}\n \n \n {{findLabelByValue(item)}}\n \n
\n {{placeholder || defaultLabel || \'empty\'}}\n \n \n
\n
\n
\n
\n \n
\n
\n \n
\n
\n \n \n - \n {{getOptionGroupLabel(optgroup)||\'empty\'}}\n \n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n - {{emptyFilterMessage}}
\n \n
\n
\n \n
\n
\n ',animations:[trigger("overlayAnimation",[transition(":enter",[style({opacity:0,transform:"scaleY(0.8)"}),animate("{{showTransitionParams}}")]),transition(":leave",[animate("{{hideTransitionParams}}",style({opacity:0}))])])],host:{"[class.p-inputwrapper-filled]":"filled","[class.p-inputwrapper-focus]":"focus || overlayVisible"},providers:[MULTISELECT_VALUE_ACCESSOR],changeDetection:ChangeDetectionStrategy.OnPush,encapsulation:ViewEncapsulation.None,styles:[".p-multiselect{-ms-user-select:none;-webkit-user-select:none;cursor:pointer;display:inline-flex;position:relative;user-select:none}.p-multiselect-trigger{align-items:center;display:flex;flex-shrink:0;justify-content:center}.p-multiselect-label-container{cursor:pointer;flex:1 1 auto;overflow:hidden}.p-multiselect-label{cursor:pointer;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.p-multiselect-label-empty{overflow:hidden;visibility:hidden}.p-multiselect-token{align-items:center;cursor:default;display:inline-flex;flex:0 0 auto}.p-multiselect-token-icon{cursor:pointer}.p-multiselect .p-multiselect-panel{min-width:100%}.p-multiselect-panel{position:absolute}.p-multiselect-items-wrapper{overflow:auto}.p-multiselect-items{list-style-type:none;margin:0;padding:0}.p-multiselect-item{align-items:center;cursor:pointer;display:flex;font-weight:400;overflow:hidden;position:relative;white-space:nowrap}.p-multiselect-header{align-items:center;display:flex;justify-content:space-between}.p-multiselect-filter-container{flex:1 1 auto;position:relative}.p-multiselect-filter-icon{margin-top:-.5rem;position:absolute;top:50%}.p-multiselect-filter-container .p-inputtext{width:100%}.p-multiselect-close{align-items:center;display:flex;flex-shrink:0;justify-content:center;overflow:hidden;position:relative}.p-fluid .p-multiselect{display:flex}"]}]}],MultiSelect.ctorParameters=(()=>[{type:ElementRef},{type:Renderer2},{type:ChangeDetectorRef},{type:FilterService}]),MultiSelect.propDecorators={style:[{type:Input}],styleClass:[{type:Input}],panelStyle:[{type:Input}],panelStyleClass:[{type:Input}],inputId:[{type:Input}],disabled:[{type:Input}],readonly:[{type:Input}],group:[{type:Input}],filter:[{type:Input}],filterPlaceHolder:[{type:Input}],filterLocale:[{type:Input}],overlayVisible:[{type:Input}],tabindex:[{type:Input}],appendTo:[{type:Input}],dataKey:[{type:Input}],name:[{type:Input}],ariaLabelledBy:[{type:Input}],displaySelectedLabel:[{type:Input}],maxSelectedLabels:[{type:Input}],selectionLimit:[{type:Input}],selectedItemsLabel:[{type:Input}],showToggleAll:[{type:Input}],emptyFilterMessage:[{type:Input}],resetFilterOnHide:[{type:Input}],dropdownIcon:[{type:Input}],optionLabel:[{type:Input}],optionValue:[{type:Input}],optionDisabled:[{type:Input}],optionGroupLabel:[{type:Input}],optionGroupChildren:[{type:Input}],showHeader:[{type:Input}],autoZIndex:[{type:Input}],baseZIndex:[{type:Input}],filterBy:[{type:Input}],virtualScroll:[{type:Input}],itemSize:[{type:Input}],showTransitionOptions:[{type:Input}],hideTransitionOptions:[{type:Input}],ariaFilterLabel:[{type:Input}],filterMatchMode:[{type:Input}],tooltip:[{type:Input}],tooltipPosition:[{type:Input}],tooltipPositionStyle:[{type:Input}],tooltipStyleClass:[{type:Input}],autofocusFilter:[{type:Input}],display:[{type:Input}],containerViewChild:[{type:ViewChild,args:["container"]}],filterInputChild:[{type:ViewChild,args:["filterInput"]}],accessibleViewChild:[{type:ViewChild,args:["in"]}],footerFacet:[{type:ContentChild,args:[Footer]}],headerFacet:[{type:ContentChild,args:[Header]}],templates:[{type:ContentChildren,args:[PrimeTemplate]}],onChange:[{type:Output}],onFocus:[{type:Output}],onBlur:[{type:Output}],onClick:[{type:Output}],onPanelShow:[{type:Output}],onPanelHide:[{type:Output}],scrollHeight:[{type:Input}],defaultLabel:[{type:Input}],placeholder:[{type:Input}],options:[{type:Input}],filterValue:[{type:Input}]};class MultiSelectModule{}MultiSelectModule.decorators=[{type:NgModule,args:[{imports:[CommonModule,SharedModule,ScrollingModule,TooltipModule,RippleModule],exports:[MultiSelect,SharedModule,ScrollingModule],declarations:[MultiSelect,MultiSelectItem]}]}];export{MULTISELECT_VALUE_ACCESSOR,MultiSelect,MultiSelectItem,MultiSelectModule};