"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple"),i=require("primereact/csstransition"),r=require("primereact/portal"),o=require("primereact/virtualscroller"),l=require("primereact/api"),s=require("primereact/tooltip"),a=require("primereact/overlayservice");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=p(e),c=p(l);function h(){return h=Object.assign||function(e){for(var t=1;t=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 V(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,i=new Array(t);n0?this.findPrevOption({group:n-1,option:this.getOptionGroupChildren(t[n-1]).length}):null)}return this.findPrevOptionInList(t,e)}},{key:"findPrevOptionInList",value:function(e,t){var n=t-1;if(n<0)return null;var i=e[n];return this.isOptionDisabled(i)?this.findPrevOption(n):i}},{key:"search",value:function(e){var t=this;this.searchTimeout&&clearTimeout(this.searchTimeout);var n=e.key;if(this.previousSearchChar=this.currentSearchChar,this.currentSearchChar=n,this.searchValue=this.previousSearchChar===this.currentSearchChar?this.currentSearchChar:this.searchValue?this.searchValue+n:n,this.searchValue){var i=this.getSelectedOptionIndex(),r=this.props.optionGroupLabel?this.searchOptionInGroup(i):this.searchOption(++i);r&&(this.selectItem({originalEvent:e,option:r}),this.selectedOptionUpdated=!0)}this.searchTimeout=setTimeout((function(){t.searchValue=null}),250)}},{key:"searchOption",value:function(e){var t;if(this.searchValue){var n=this.getVisibleOptions();(t=this.searchOptionInRange(e,n.length))||(t=this.searchOptionInRange(0,e))}return t}},{key:"searchOptionInRange",value:function(e,t){for(var n=this.getVisibleOptions(),i=e;i0}},{key:"getOptionLabel",value:function(e){return this.props.optionLabel?t.ObjectUtils.resolveFieldData(e,this.props.optionLabel):e&&void 0!==e.label?e.label:e}},{key:"getOptionValue",value:function(e){return this.props.optionValue?t.ObjectUtils.resolveFieldData(e,this.props.optionValue):e&&void 0!==e.value?e.value:e}},{key:"getOptionRenderKey",value:function(e){return this.props.dataKey?t.ObjectUtils.resolveFieldData(e,this.props.dataKey):this.getOptionLabel(e)}},{key:"isOptionDisabled",value:function(e){return this.props.optionDisabled?t.ObjectUtils.isFunction(this.props.optionDisabled)?this.props.optionDisabled(e):t.ObjectUtils.resolveFieldData(e,this.props.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled}},{key:"getOptionGroupRenderKey",value:function(e){return t.ObjectUtils.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(e){return t.ObjectUtils.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(e){return t.ObjectUtils.resolveFieldData(e,this.props.optionGroupChildren)}},{key:"checkValidity",value:function(){return!!this.inputRef.current&&this.inputRef.current.checkValidity()}},{key:"isLazy",value:function(){return this.props.virtualScrollerOptions&&this.props.virtualScrollerOptions.lazy}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()&&!this.isLazy()){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=j(this.props.options);try{for(r.s();!(n=r.n()).done;){var o=n.value,s=l.FilterService.filter(this.getOptionGroupChildren(o),t,e,this.props.filterMatchMode,this.props.filterLocale);s&&s.length&&i.push(D(D({},o),{items:s}))}}catch(e){r.e(e)}finally{r.f()}return i}return l.FilterService.filter(this.props.options,t,e,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"updateInputField",value:function(){if(this.props.editable&&this.input){var e=this.getSelectedOption(),t=e?this.getOptionLabel(e):null;this.input.value=t||this.props.value||""}}},{key:"updateInputRef",value:function(){var e=this.props.inputRef;e&&("function"==typeof e?e(this.inputRef.current):e.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.props.autoFocus&&this.focusInput&&this.focusInput.focus(),this.props.tooltip&&this.renderTooltip(),this.updateInputField(),this.inputRef.current&&(this.inputRef.current.selectedIndex=1)}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=null),this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null),t.ZIndexUtils.clear(this.overlayRef.current)}},{key:"componentDidUpdate",value:function(e){this.state.overlayVisible&&(this.props.filter&&this.alignOverlay(),e.value!==this.props.value&&this.scrollInView()),e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(D({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip()),!this.state.filter||this.props.options&&0!==this.props.options.length||this.setState({filter:""}),this.updateInputField(),this.inputRef.current&&(this.inputRef.current.selectedIndex=1)}},{key:"renderHiddenSelect",value:function(e){var t=u.default.createElement("option",{value:""},this.props.placeholder),n=e?u.default.createElement("option",{value:e.value},this.getOptionLabel(e)):null;return u.default.createElement("div",{className:"p-hidden-accessible p-dropdown-hidden-select"},u.default.createElement("select",{ref:this.inputRef,required:this.props.required,name:this.props.name,tabIndex:-1,"aria-hidden":"true"},t,n))}},{key:"renderTooltip",value:function(){this.tooltip=s.tip({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderKeyboardHelper",value:function(){var e=this;return u.default.createElement("div",{className:"p-hidden-accessible"},u.default.createElement("input",{ref:function(t){return e.focusInput=t},id:this.props.inputId,type:"text",readOnly:!0,"aria-haspopup":"listbox",onFocus:this.onInputFocus,onBlur:this.onInputBlur,onKeyDown:this.onInputKeyDown,disabled:this.props.disabled,tabIndex:this.props.tabIndex,"aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy}))}},{key:"renderLabel",value:function(e){var n=this,i=t.ObjectUtils.isNotEmpty(e)?this.getOptionLabel(e):null;if(this.props.editable)return u.default.createElement("input",{ref:function(e){return n.input=e},type:"text",defaultValue:i||this.props.value||"",className:"p-dropdown-label p-inputtext",disabled:this.props.disabled,placeholder:this.props.placeholder,maxLength:this.props.maxLength,onInput:this.onEditableInputChange,onFocus:this.onEditableInputFocus,onBlur:this.onInputBlur,"aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy,"aria-haspopup":"listbox"});var r=t.classNames("p-dropdown-label p-inputtext",{"p-placeholder":null===i&&this.props.placeholder,"p-dropdown-label-empty":null===i&&!this.props.placeholder}),o=this.props.valueTemplate?t.ObjectUtils.getJSXElement(this.props.valueTemplate,e,this.props):i||this.props.placeholder||"empty";return u.default.createElement("span",{ref:function(e){return n.input=e},className:r},o)}},{key:"renderClearIcon",value:function(){return null!=this.props.value&&this.props.showClear&&!this.props.disabled?u.default.createElement("i",{className:"p-dropdown-clear-icon pi pi-times",onClick:this.clear}):null}},{key:"renderDropdownIcon",value:function(){var e=this,n=t.classNames("p-dropdown-trigger-icon p-clickable",this.props.dropdownIcon);return u.default.createElement("div",{ref:function(t){return e.trigger=t},className:"p-dropdown-trigger",role:"button","aria-haspopup":"listbox","aria-expanded":this.state.overlayVisible},u.default.createElement("span",{className:n}))}},{key:"render",value:function(){var e=this,n=t.classNames("p-dropdown p-component p-inputwrapper",this.props.className,{"p-disabled":this.props.disabled,"p-focus":this.state.focused,"p-dropdown-clearable":this.props.showClear&&!this.props.disabled,"p-inputwrapper-filled":this.props.value,"p-inputwrapper-focus":this.state.focused||this.state.overlayVisible}),i=this.getVisibleOptions(),r=this.getSelectedOption(),o=this.props.appendTo||c.default.appendTo,l=this.renderHiddenSelect(r),s=this.renderKeyboardHelper(),a=this.renderLabel(r),p=this.renderDropdownIcon(),d=this.renderClearIcon();return u.default.createElement("div",{id:this.props.id,ref:function(t){return e.container=t},className:n,style:this.props.style,onClick:this.onClick,onMouseDown:this.props.onMouseDown,onContextMenu:this.props.onContextMenu},s,l,a,d,p,u.default.createElement(R,h({ref:this.overlayRef,visibleOptions:i},this.props,{appendTo:o,onClick:this.onPanelClick,onOptionClick:this.onOptionClick,filterValue:this.state.filter,hasFilter:this.hasFilter,onFilterClearIconClick:this.onFilterClearIconClick,onFilterInputKeyDown:this.onFilterInputKeyDown,onFilterInputChange:this.onFilterInputChange,getOptionLabel:this.getOptionLabel,getOptionRenderKey:this.getOptionRenderKey,isOptionDisabled:this.isOptionDisabled,getOptionGroupChildren:this.getOptionGroupChildren,getOptionGroupLabel:this.getOptionGroupLabel,getOptionGroupRenderKey:this.getOptionGroupRenderKey,isSelected:this.isSelected,getSelectedOptionIndex:this.getSelectedOptionIndex,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited})))}}]),p}();C(G,"defaultProps",{id:null,inputRef:null,name:null,value:null,options:null,optionLabel:null,optionValue:null,optionDisabled:null,optionGroupLabel:null,optionGroupChildren:null,optionGroupTemplate:null,valueTemplate:null,itemTemplate:null,style:null,className:null,virtualScrollerOptions:null,scrollHeight:"200px",filter:!1,filterBy:null,filterMatchMode:"contains",filterPlaceholder:null,filterLocale:void 0,emptyMessage:null,emptyFilterMessage:null,editable:!1,placeholder:null,required:!1,disabled:!1,appendTo:null,tabIndex:null,autoFocus:!1,filterInputAutoFocus:!0,resetFilterOnHide:!1,showFilterClear:!1,panelClassName:null,panelStyle:null,dataKey:null,inputId:null,showClear:!1,maxLength:null,tooltip:null,tooltipOptions:null,ariaLabel:null,ariaLabelledBy:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",showOnFocus:!1,onChange:null,onFocus:null,onBlur:null,onMouseDown:null,onContextMenu:null,onShow:null,onHide:null,onFilter:null}),exports.Dropdown=G;