import e,{createRef as t,Component as n}from"react";import{classNames as i,IconUtils as r,ObjectUtils as o,DomHandler as l,ZIndexUtils as s,ConnectedOverlayScrollHandler as p}from"primereact/utils";import{tip as a}from"primereact/tooltip";import{CSSTransition as c}from"primereact/csstransition";import{Portal as u}from"primereact/portal";import{InputText as h}from"primereact/inputtext";import{Ripple as f}from"primereact/ripple";import{VirtualScroller as d}from"primereact/virtualscroller";import y,{localeOption as v,FilterService as m}from"primereact/api";import{OverlayService as b}from"primereact/overlayservice";function O(){return O=Object.assign||function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,i=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){s=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(s)throw o}}}}function Q(e,t){if(e){if("string"==typeof e)return Y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Y(e,t):void 0}}function Y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n0}},{key:"isAllSelected",value:function(){var e=this;if(this.props.onSelectAll)return this.props.selectAll;var t=this.getVisibleOptions();if(o.isEmpty(t))return!1;if(t=t.filter((function(t){return!e.isOptionDisabled(t)})),this.props.optionGroupLabel){var n,i=Z(t);try{for(i.s();!(n=i.n()).done;){var r,l=this.getOptionGroupChildren(n.value).filter((function(t){return!e.isOptionDisabled(t)})),s=Z(l);try{for(s.s();!(r=s.n()).done;){if(!this.isSelected(r.value))return!1}}catch(e){s.e(e)}finally{s.f()}}}catch(e){i.e(e)}finally{i.f()}}else{var p,a=Z(t);try{for(a.s();!(p=a.n()).done;){if(!this.isSelected(p.value))return!1}}catch(e){a.e(e)}finally{a.f()}}return!0}},{key:"getOptionLabel",value:function(e){return this.props.optionLabel?o.resolveFieldData(e,this.props.optionLabel):e&&void 0!==e.label?e.label:e}},{key:"getOptionValue",value:function(e){if(this.props.optionValue){var t=o.resolveFieldData(e,this.props.optionValue);return null!==t?t:e}return e&&void 0!==e.value?e.value:e}},{key:"getOptionRenderKey",value:function(e){return this.props.dataKey?o.resolveFieldData(e,this.props.dataKey):this.getOptionLabel(e)}},{key:"getOptionGroupRenderKey",value:function(e){return o.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(e){return o.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(e){return o.resolveFieldData(e,this.props.optionGroupChildren)}},{key:"isOptionDisabled",value:function(e){return this.props.optionDisabled?o.isFunction(this.props.optionDisabled)?this.props.optionDisabled(e):o.resolveFieldData(e,this.props.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled}},{key:"isOptionValueUsed",value:function(e){return this.props.optionValue||e&&void 0!==e.value}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()){var e=this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale),t=this.props.filterBy?this.props.filterBy.split(","):[this.props.optionLabel||"label"];if(this.props.optionGroupLabel){var n,i=[],r=Z(this.props.options);try{for(r.s();!(n=r.n()).done;){var o=n.value,l=m.filter(this.getOptionGroupChildren(o),t,e,this.props.filterMatchMode,this.props.filterLocale);l&&l.length&&i.push($($({},o),{items:l}))}}catch(e){r.e(e)}finally{r.f()}return i}return m.filter(this.props.options,t,e,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"isEmpty",value:function(){return!this.props.value||0===this.props.value.length}},{key:"equalityKey",value:function(){return this.props.optionValue?null:this.props.dataKey}},{key:"checkValidity",value:function(){return this.inputRef.current.checkValidity()}},{key:"removeChip",value:function(e,t){var n=this.equalityKey(),i=this.props.value.filter((function(e){return!o.equals(e,t,n)}));this.updateModel(e,i)}},{key:"getSelectedItemsLabel",value:function(){var e=/{(.*?)}/;return e.test(this.props.selectedItemsLabel)?this.props.selectedItemsLabel.replace(this.props.selectedItemsLabel.match(e)[0],this.props.value.length+""):this.props.selectedItemsLabel}},{key:"getLabel",value:function(){var e;if(!this.isEmpty()&&!this.props.fixedPlaceholder){if(this.props.maxSelectedLabels&&this.props.value.length>this.props.maxSelectedLabels)return this.getSelectedItemsLabel();e="";for(var t=0;tthis.props.maxSelectedLabels?this.getSelectedItemsLabel():this.props.value.map((function(n,i){var r=o.getJSXElement(t.props.selectedItemTemplate,n);return e.createElement(e.Fragment,{key:i},r)})):"chip"!==this.props.display||this.isEmpty()?this.getLabel():this.props.value.slice(0,this.props.maxSelectedLabels||this.props.value.length).map((function(n){var i=t.getLabelByValue(n);return e.createElement("div",{className:"p-multiselect-token",key:i},e.createElement("span",{className:"p-multiselect-token-label"},i),!t.props.disabled&&r.getJSXIcon(t.props.removeIcon,{className:"p-multiselect-token-icon",onClick:function(e){return t.removeChip(e,n)}},{props:t.props}))}))}},{key:"renderTooltip",value:function(){this.tooltip=a({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderClearIcon",value:function(){var t=this;return this.isEmpty()||!this.props.showClear||this.props.disabled?null:e.createElement("i",{className:"p-multiselect-clear-icon pi pi-times",onClick:function(e){return t.updateModel(e,null)}})}},{key:"renderLabel",value:function(){var t=this,n=this.isEmpty(),r=this.getLabelContent(),o=i("p-multiselect-label",{"p-placeholder":n&&this.props.placeholder,"p-multiselect-label-empty":n&&!this.props.placeholder&&!this.props.selectedItemTemplate,"p-multiselect-items-label":!n&&"chip"!==this.props.display&&this.props.value.length>this.props.maxSelectedLabels});return e.createElement("div",{ref:function(e){return t.label=e},className:"p-multiselect-label-container"},e.createElement("div",{className:o},r||this.props.placeholder||"empty"))}},{key:"render",value:function(){var t=this,n=i("p-multiselect p-component p-inputwrapper",{"p-multiselect-chip":"chip"===this.props.display,"p-disabled":this.props.disabled,"p-multiselect-clearable":this.props.showClear&&!this.props.disabled,"p-focus":this.state.focused,"p-inputwrapper-filled":this.props.value&&this.props.value.length>0,"p-inputwrapper-focus":this.state.focused||this.state.overlayVisible},this.props.className),o=this.getVisibleOptions(),l=this.renderLabel(),s=this.renderClearIcon();return e.createElement("div",{id:this.props.id,className:n,onClick:this.onClick,ref:function(e){return t.container=e},style:this.props.style},e.createElement("div",{className:"p-hidden-accessible"},e.createElement("input",{ref:this.inputRef,id:this.props.inputId,name:this.props.name,readOnly:!0,type:"text",onFocus:this.onFocus,onBlur:this.onBlur,onKeyDown:this.onKeyDown,role:"listbox","aria-haspopup":"listbox","aria-labelledby":this.props.ariaLabelledBy,"aria-expanded":this.state.overlayVisible,disabled:this.props.disabled,tabIndex:this.props.tabIndex})),l,s,e.createElement("div",{className:"p-multiselect-trigger"},r.getJSXIcon(this.props.dropdownIcon,{className:"p-multiselect-trigger-icon p-c"},{props:this.props})),e.createElement(U,O({ref:this.overlayRef,visibleOptions:o},this.props,{onClick:this.onPanelClick,onOverlayHide:this.hide,filterValue:this.state.filter,hasFilter:this.hasFilter,onFilterInputChange:this.onFilterInputChange,onCloseClick:this.onCloseClick,onSelectAll:this.onSelectAll,getOptionLabel:this.getOptionLabel,getOptionRenderKey:this.getOptionRenderKey,isOptionDisabled:this.isOptionDisabled,getOptionGroupChildren:this.getOptionGroupChildren,getOptionGroupLabel:this.getOptionGroupLabel,getOptionGroupRenderKey:this.getOptionGroupRenderKey,isSelected:this.isSelected,getSelectedOptionIndex:this.getSelectedOptionIndex,isAllSelected:this.isAllSelected,onOptionSelect:this.onOptionSelect,allowOptionSelect:this.allowOptionSelect,onOptionKeyDown:this.onOptionKeyDown,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited})))}}]),d}();j(te,"defaultProps",{id:null,inputRef:null,name:null,value:null,options:null,optionLabel:null,optionValue:null,optionDisabled:null,optionGroupLabel:null,optionGroupChildren:null,optionGroupTemplate:null,display:"comma",style:null,className:null,panelClassName:null,panelStyle:null,virtualScrollerOptions:null,scrollHeight:"200px",placeholder:null,fixedPlaceholder:!1,disabled:!1,showClear:!1,filter:!1,filterBy:null,filterMatchMode:"contains",filterPlaceholder:null,filterLocale:void 0,emptyFilterMessage:null,resetFilterOnHide:!1,tabIndex:0,dataKey:null,inputId:null,appendTo:null,tooltip:null,tooltipOptions:null,maxSelectedLabels:null,selectionLimit:null,selectedItemsLabel:"{0} items selected",ariaLabelledBy:null,itemTemplate:null,selectedItemTemplate:null,panelHeaderTemplate:null,panelFooterTemplate:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",removeIcon:"pi pi-times-circle",showSelectAll:!0,selectAll:!1,onChange:null,onFocus:null,onBlur:null,onShow:null,onHide:null,onFilter:null,onSelectAll:null});export{te as MultiSelect};