import t,{Component as e}from"react";import{FilterService as n}from"primereact/api";import{DomHandler as o,classNames as r,ObjectUtils as i}from"primereact/utils";import{Ripple as l}from"primereact/ripple";import{InputText as a}from"primereact/inputtext";import{tip as s}from"primereact/tooltip";import{VirtualScroller as p}from"primereact/virtualscroller";function u(){return u=Object.assign||function(t){for(var e=1;et.length)&&(e=t.length);for(var n=0,o=new Array(e);n=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},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 i,l=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return l=t.done,t},e:function(t){a=!0,i=t},f:function(){try{l||null==n.return||n.return()}finally{if(a)throw i}}}}function j(t,e){if(t){if("string"==typeof t)return V(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?V(t,e):void 0}}function V(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n-1}},{key:"hasFilter",value:function(){var t=this.getFilterValue();return t&&t.trim().length>0}},{key:"getOptionLabel",value:function(t){return this.props.optionLabel?i.resolveFieldData(t,this.props.optionLabel):t&&void 0!==t.label?t.label:t}},{key:"getOptionValue",value:function(t){return this.props.optionValue?i.resolveFieldData(t,this.props.optionValue):t&&void 0!==t.value?t.value:t}},{key:"getOptionRenderKey",value:function(t){return this.props.dataKey?i.resolveFieldData(t,this.props.dataKey):this.getOptionLabel(t)}},{key:"isOptionDisabled",value:function(t){return this.props.optionDisabled?i.isFunction(this.props.optionDisabled)?this.props.optionDisabled(t):i.resolveFieldData(t,this.props.optionDisabled):!(!t||void 0===t.disabled)&&t.disabled}},{key:"getOptionGroupRenderKey",value:function(t){return i.resolveFieldData(t,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(t){return i.resolveFieldData(t,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(t){return i.resolveFieldData(t,this.props.optionGroupChildren)}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()){var t=this.getFilterValue().trim().toLocaleLowerCase(this.props.filterLocale),e=this.props.filterBy?this.props.filterBy.split(","):[this.props.optionLabel||"label"];if(this.props.optionGroupLabel){var o,r=[],i=P(this.props.options);try{for(i.s();!(o=i.n()).done;){var l=o.value,a=n.filter(this.getOptionGroupChildren(l),e,t,this.props.filterMatchMode,this.props.filterLocale);a&&a.length&&r.push(K(K({},l),{items:a}))}}catch(t){i.e(t)}finally{i.f()}return r}return n.filter(this.props.options,e,t,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"renderGroupChildren",value:function(e){var n=this;return this.getOptionGroupChildren(e).map((function(e,o){var r=n.getOptionLabel(e),i=o+"_"+n.getOptionRenderKey(e),l=n.isOptionDisabled(e),a=l?null:n.props.tabIndex||0;return t.createElement(L,{key:i,label:r,option:e,template:n.props.itemTemplate,selected:n.isSelected(e),onClick:n.onOptionSelect,onTouchEnd:n.onOptionTouchEnd,tabIndex:a,disabled:l})}))}},{key:"renderItem",value:function(e,n){if(this.props.optionGroupLabel){var o=this.props.optionGroupTemplate?i.getJSXElement(this.props.optionGroupTemplate,e,n):this.getOptionGroupLabel(e),r=this.renderGroupChildren(e),l=n+"_"+this.getOptionGroupRenderKey(e);return t.createElement(t.Fragment,{key:l},t.createElement("li",{className:"p-listbox-item-group"},o),r)}var a=this.getOptionLabel(e),s=n+"_"+this.getOptionRenderKey(e),p=this.isOptionDisabled(e),u=p?null:this.props.tabIndex||0;return t.createElement(L,{key:s,label:a,option:e,template:this.props.itemTemplate,selected:this.isSelected(e),onClick:this.onOptionSelect,onTouchEnd:this.onOptionTouchEnd,tabIndex:u,disabled:p})}},{key:"renderItems",value:function(t){var e=this;return t&&t.length?t.map((function(t,n){return e.renderItem(t,n)})):null}},{key:"renderList",value:function(e){var n=this;if(this.props.virtualScrollerOptions){var o=K(K({},this.props.virtualScrollerOptions),{items:e,onLazyLoad:function(t){return n.props.virtualScrollerOptions.onLazyLoad(K(K({},t),{filter:n.getFilterValue()}))},itemTemplate:function(t,e){return t&&n.renderItem(t,e.index)},contentTemplate:function(e){var o=r("p-listbox-list",e.className);return t.createElement("ul",{ref:e.contentRef,className:o,role:"listbox","aria-multiselectable":n.props.multiple},e.children)}});return t.createElement(p,u({ref:function(t){return n.virtualScrollerRef=t}},o))}var i=this.renderItems(e);return t.createElement("ul",{className:"p-listbox-list",role:"listbox","aria-multiselectable":this.props.multiple},i)}},{key:"render",value:function(){var e,n=this,o=r("p-listbox p-component",{"p-disabled":this.props.disabled},this.props.className),i=r("p-listbox-list-wrapper",this.props.listClassName),l=this.getVisibleOptions(),a=this.renderList(l);return this.props.filter&&(e=t.createElement(F,{filter:this.getFilterValue(),onFilter:this.onFilter,disabled:this.props.disabled,filterPlaceholder:this.props.filterPlaceholder})),t.createElement("div",{ref:function(t){return n.element=t},id:this.props.id,className:o,style:this.props.style},e,t.createElement("div",{ref:function(t){return n.wrapper=t},className:i,style:this.props.listStyle},a))}}]),f}();x(G,"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});export{G as ListBox};