import e,{Component as t,createRef as n}from"react";import{InputText as r}from"primereact/inputtext";import{Button as i}from"primereact/button";import{ObjectUtils as o,classNames as s,ZIndexUtils as l,DomHandler as p,ConnectedOverlayScrollHandler as u,UniqueComponentId as a,IconUtils as c}from"primereact/utils";import{Ripple as h}from"primereact/ripple";import{CSSTransition as d}from"primereact/csstransition";import{Portal as f}from"primereact/portal";import{VirtualScroller as m}from"primereact/virtualscroller";import{tip as v}from"primereact/tooltip";import{OverlayService as y}from"primereact/overlayservice";import g from"primereact/api";function b(){return b=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:i}}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,s=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){l=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(l)throw o}}}}function V(e,t){if(e){if("string"==typeof e)return _(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)?_(e,t):void 0}}function _(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=this.props.minLength?this.timeout=setTimeout((function(){t.search(e,n,"input")}),this.props.delay):this.hideOverlay()}},{key:"search",value:function(e,t,n){null!=t&&("input"===n&&0===t.trim().length||this.props.completeMethod&&(this.setState({searching:!0}),this.props.completeMethod({originalEvent:e,query:t})))}},{key:"selectItem",value:function(e,t,n){if(this.props.multiple){if(this.inputRef.current.value="",!this.isSelected(t)){var r=this.props.value?[].concat(O(i=this.props.value)||C(i)||I(i)||w(),[t]):[t];this.updateModel(e,r)}}else this.updateInputField(t),this.updateModel(e,t);var i;this.props.onSelect&&this.props.onSelect({originalEvent:e,value:t}),n||(this.inputRef.current.focus(),this.hideOverlay())}},{key:"updateModel",value:function(e,t){this.props.onChange&&this.props.onChange({originalEvent:e,value:t,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.state.id,value:t}}),this.ariaSelected=t}},{key:"formatValue",value:function(e){if(e){if(this.props.selectedItemTemplate&&(this.props.multiple?this.isSelected(e):this.findOptionIndex(e)>-1)){var t=o.getJSXElement(this.props.selectedItemTemplate,e);return t||e}if(this.props.field){var n=o.resolveFieldData(e,this.props.field);return null!=n?n:e}return e}return""}},{key:"updateInputField",value:function(e){var t=this.formatValue(e);this.inputRef.current.value=t}},{key:"showOverlay",value:function(){this.setState({overlayVisible:!0})}},{key:"hideOverlay",value:function(){this.setState({overlayVisible:!1,searching:!1})}},{key:"onOverlayEnter",value:function(){l.set("overlay",this.overlayRef.current,g.autoZIndex,g.zIndex.overlay),this.alignOverlay()}},{key:"onOverlayEntering",value:function(){this.props.autoHighlight&&this.props.suggestions&&this.props.suggestions.length&&p.addClass(this.overlayRef.current.firstChild.firstChild,"p-highlight")}},{key:"onOverlayEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.props.onShow&&this.props.onShow()}},{key:"onOverlayExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onOverlayExited",value:function(){l.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){p.alignOverlay(this.overlayRef.current,this.props.multiple?this.multiContainer:this.inputRef.current,this.props.appendTo||g.appendTo)}},{key:"onPanelClick",value:function(e){y.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"onDropdownClick",value:function(e){this.inputRef.current.focus(),"blank"===this.props.dropdownMode?this.search(e,"","dropdown"):"current"===this.props.dropdownMode&&this.search(e,this.inputRef.current.value,"dropdown"),this.props.onDropdownClick&&this.props.onDropdownClick({originalEvent:e,query:this.inputRef.current.value})}},{key:"removeItem",value:function(e,t){var n=this.props.value[t],r=this.props.value.filter((function(e,n){return t!==n}));this.updateModel(e,r),this.props.onUnselect&&this.props.onUnselect({originalEvent:e,value:n})}},{key:"onInputKeyDown",value:function(e){if(this.state.overlayVisible){var t=p.findSingle(this.overlayRef.current,"li.p-highlight");switch(e.which){case 40:if(t){var n=this.findNextItem(t);n&&(p.addClass(n,"p-highlight"),p.removeClass(t,"p-highlight"),p.scrollInView(this.overlayRef.current,n))}else t=p.findSingle(this.overlayRef.current,"li"),p.hasClass(t,"p-autocomplete-item-group")&&(t=this.findNextItem(t)),t&&p.addClass(t,"p-highlight");e.preventDefault();break;case 38:if(t){var r=this.findPrevItem(t);r&&(p.addClass(r,"p-highlight"),p.removeClass(t,"p-highlight"),p.scrollInView(this.overlayRef.current,r))}e.preventDefault();break;case 13:t&&(this.selectHighlightItem(e,t),this.hideOverlay()),e.preventDefault();break;case 27:this.hideOverlay(),e.preventDefault();break;case 9:t&&this.selectHighlightItem(e,t),this.hideOverlay()}}if(this.props.multiple&&8===e.which)if(this.props.value&&this.props.value.length&&!this.inputRef.current.value){var i=this.props.value[this.props.value.length-1],o=this.props.value.slice(0,-1);this.updateModel(e,o),this.props.onUnselect&&this.props.onUnselect({originalEvent:e,value:i})}}},{key:"selectHighlightItem",value:function(e,t){this.props.optionGroupLabel?this.selectItem(e,this.getOptionGroupChildren(this.props.suggestions[t.dataset.group])[t.dataset.index]):this.selectItem(e,this.props.suggestions[p.index(t)])}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?p.hasClass(t,"p-autocomplete-item-group")?this.findNextItem(t):t:null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?p.hasClass(t,"p-autocomplete-item-group")?this.findPrevItem(t):t:null}},{key:"onInputFocus",value:function(e){var t=this;e.persist(),this.setState({focused:!0},(function(){t.props.onFocus&&t.props.onFocus(e)}))}},{key:"forceItemSelection",value:function(e){var t=!1,n=e.target.value.trim();if(this.props.suggestions){var r,i=A(this.props.suggestions);try{for(i.s();!(r=i.n()).done;){var s=r.value,l=this.props.field?o.resolveFieldData(s,this.props.field):s;if(l&&n===l.trim()){t=!0,this.selectItem(e,s,!0);break}}}catch(e){i.e(e)}finally{i.f()}}t||(this.inputRef.current.value="",this.updateModel(e,null),this.props.onClear&&this.props.onClear(e))}},{key:"onInputBlur",value:function(e){var t=this;e.persist(),this.setState({focused:!1},(function(){t.props.forceSelection&&t.forceItemSelection(e),t.props.onBlur&&t.props.onBlur(e)}))}},{key:"onMultiContainerClick",value:function(e){this.inputRef.current.focus(),this.props.onClick&&this.props.onClick(e)}},{key:"onMultiInputFocus",value:function(e){this.onInputFocus(e),p.addClass(this.multiContainer,"p-focus")}},{key:"onMultiInputBlur",value:function(e){this.onInputBlur(e),p.removeClass(this.multiContainer,"p-focus")}},{key:"isSelected",value:function(e){var t=!1;if(this.props.value&&this.props.value.length)for(var n=0;n