"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),n=require("primereact/utils"),r=require("primereact/ripple"),o=require("primereact/inputtext"),i=require("primereact/tooltip"),l=require("primereact/virtualscroller");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=a(e);function p(){return p=Object.assign||function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}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 i,l=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){a=!0,i=e},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw i}}}}function L(e,t){if(e){if("string"==typeof e)return P(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)?P(e,t):void 0}}function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n-1}},{key:"hasFilter",value:function(){var e=this.getFilterValue();return e&&e.trim().length>0}},{key:"getOptionLabel",value:function(e){return this.props.optionLabel?n.ObjectUtils.resolveFieldData(e,this.props.optionLabel):e&&void 0!==e.label?e.label:e}},{key:"getOptionValue",value:function(e){return this.props.optionValue?n.ObjectUtils.resolveFieldData(e,this.props.optionValue):e&&void 0!==e.value?e.value:e}},{key:"getOptionRenderKey",value:function(e){return this.props.dataKey?n.ObjectUtils.resolveFieldData(e,this.props.dataKey):this.getOptionLabel(e)}},{key:"isOptionDisabled",value:function(e){return this.props.optionDisabled?n.ObjectUtils.isFunction(this.props.optionDisabled)?this.props.optionDisabled(e):n.ObjectUtils.resolveFieldData(e,this.props.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled}},{key:"getOptionGroupRenderKey",value:function(e){return n.ObjectUtils.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(e){return n.ObjectUtils.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(e){return n.ObjectUtils.resolveFieldData(e,this.props.optionGroupChildren)}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()){var e=this.getFilterValue().trim().toLocaleLowerCase(this.props.filterLocale),n=this.props.filterBy?this.props.filterBy.split(","):[this.props.optionLabel||"label"];if(this.props.optionGroupLabel){var r,o=[],i=F(this.props.options);try{for(i.s();!(r=i.n()).done;){var l=r.value,a=t.FilterService.filter(this.getOptionGroupChildren(l),n,e,this.props.filterMatchMode,this.props.filterLocale);a&&a.length&&o.push(I(I({},l),{items:a}))}}catch(e){i.e(e)}finally{i.f()}return o}return t.FilterService.filter(this.props.options,n,e,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"renderGroupChildren",value:function(e){var t=this;return this.getOptionGroupChildren(e).map((function(e,n){var r=t.getOptionLabel(e),o=n+"_"+t.getOptionRenderKey(e),i=t.isOptionDisabled(e),l=i?null:t.props.tabIndex||0;return s.default.createElement(x,{key:o,label:r,option:e,template:t.props.itemTemplate,selected:t.isSelected(e),onClick:t.onOptionSelect,onTouchEnd:t.onOptionTouchEnd,tabIndex:l,disabled:i})}))}},{key:"renderItem",value:function(e,t){if(this.props.optionGroupLabel){var r=this.props.optionGroupTemplate?n.ObjectUtils.getJSXElement(this.props.optionGroupTemplate,e,t):this.getOptionGroupLabel(e),o=this.renderGroupChildren(e),i=t+"_"+this.getOptionGroupRenderKey(e);return s.default.createElement(s.default.Fragment,{key:i},s.default.createElement("li",{className:"p-listbox-item-group"},r),o)}var l=this.getOptionLabel(e),a=t+"_"+this.getOptionRenderKey(e),p=this.isOptionDisabled(e),u=p?null:this.props.tabIndex||0;return s.default.createElement(x,{key:a,label:l,option:e,template:this.props.itemTemplate,selected:this.isSelected(e),onClick:this.onOptionSelect,onTouchEnd:this.onOptionTouchEnd,tabIndex:u,disabled:p})}},{key:"renderItems",value:function(e){var t=this;return e&&e.length?e.map((function(e,n){return t.renderItem(e,n)})):null}},{key:"renderList",value:function(e){var t=this;if(this.props.virtualScrollerOptions){var r=I(I({},this.props.virtualScrollerOptions),{items:e,onLazyLoad:function(e){return t.props.virtualScrollerOptions.onLazyLoad(I(I({},e),{filter:t.getFilterValue()}))},itemTemplate:function(e,n){return e&&t.renderItem(e,n.index)},contentTemplate:function(e){var r=n.classNames("p-listbox-list",e.className);return s.default.createElement("ul",{ref:e.contentRef,className:r,role:"listbox","aria-multiselectable":t.props.multiple},e.children)}});return s.default.createElement(l.VirtualScroller,p({ref:function(e){return t.virtualScrollerRef=e}},r))}var o=this.renderItems(e);return s.default.createElement("ul",{className:"p-listbox-list",role:"listbox","aria-multiselectable":this.props.multiple},o)}},{key:"render",value:function(){var e,t=this,r=n.classNames("p-listbox p-component",{"p-disabled":this.props.disabled},this.props.className),o=n.classNames("p-listbox-list-wrapper",this.props.listClassName),i=this.getVisibleOptions(),l=this.renderList(i);return this.props.filter&&(e=s.default.createElement(T,{filter:this.getFilterValue(),onFilter:this.onFilter,disabled:this.props.disabled,filterPlaceholder:this.props.filterPlaceholder})),s.default.createElement("div",{ref:function(e){return t.element=e},id:this.props.id,className:r,style:this.props.style},e,s.default.createElement("div",{ref:function(e){return t.wrapper=e},className:o,style:this.props.listStyle},l))}}]),c}();C(K,"defaultProps",{id:null,value:null,options:null,optionLabel:null,optionValue:null,optionDisabled:null,optionGroupLabel:null,optionGroupChildren:null,optionGroupTemplate:null,itemTemplate:null,style:null,listStyle:null,listClassName:null,className:null,virtualScrollerOptions:null,disabled:null,dataKey:null,multiple:!1,metaKeySelection:!1,filter:!1,filterBy:null,filterValue:null,filterMatchMode:"contains",filterPlaceholder:null,filterLocale:void 0,tabIndex:0,tooltip:null,tooltipOptions:null,ariaLabelledBy:null,onChange:null,onFilterValueChange:null}),exports.ListBox=K;