"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/inputtext"),n=require("primereact/button"),r=require("primereact/utils"),i=require("primereact/ripple"),o=require("primereact/csstransition"),l=require("primereact/portal"),s=require("primereact/virtualscroller"),p=require("primereact/tooltip"),a=require("primereact/overlayservice"),u=require("primereact/api");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=c(e),d=c(u);function f(){return f=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,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 G(e,t){if(e){if("string"==typeof e)return F(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)?F(e,t):void 0}}function F(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(v(i=this.props.value)||y(i)||b(i)||g(),[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=r.ObjectUtils.getJSXElement(this.props.selectedItemTemplate,e);return t||e}if(this.props.field){var n=r.ObjectUtils.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(){r.ZIndexUtils.set("overlay",this.overlayRef.current,d.default.autoZIndex,d.default.zIndex.overlay),this.alignOverlay()}},{key:"onOverlayEntering",value:function(){this.props.autoHighlight&&this.props.suggestions&&this.props.suggestions.length&&r.DomHandler.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(){r.ZIndexUtils.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){r.DomHandler.alignOverlay(this.overlayRef.current,this.props.multiple?this.multiContainer:this.inputRef.current,this.props.appendTo||d.default.appendTo)}},{key:"onPanelClick",value:function(e){a.OverlayService.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=r.DomHandler.findSingle(this.overlayRef.current,"li.p-highlight");switch(e.which){case 40:if(t){var n=this.findNextItem(t);n&&(r.DomHandler.addClass(n,"p-highlight"),r.DomHandler.removeClass(t,"p-highlight"),r.DomHandler.scrollInView(this.overlayRef.current,n))}else t=r.DomHandler.findSingle(this.overlayRef.current,"li"),r.DomHandler.hasClass(t,"p-autocomplete-item-group")&&(t=this.findNextItem(t)),t&&r.DomHandler.addClass(t,"p-highlight");e.preventDefault();break;case 38:if(t){var i=this.findPrevItem(t);i&&(r.DomHandler.addClass(i,"p-highlight"),r.DomHandler.removeClass(t,"p-highlight"),r.DomHandler.scrollInView(this.overlayRef.current,i))}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 o=this.props.value[this.props.value.length-1],l=this.props.value.slice(0,-1);this.updateModel(e,l),this.props.onUnselect&&this.props.onUnselect({originalEvent:e,value:o})}}},{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[r.DomHandler.index(t)])}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?r.DomHandler.hasClass(t,"p-autocomplete-item-group")?this.findNextItem(t):t:null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?r.DomHandler.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 i,o=U(this.props.suggestions);try{for(o.s();!(i=o.n()).done;){var l=i.value,s=this.props.field?r.ObjectUtils.resolveFieldData(l,this.props.field):l;if(s&&n===s.trim()){t=!0,this.selectItem(e,l,!0);break}}}catch(e){o.e(e)}finally{o.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),r.DomHandler.addClass(this.multiContainer,"p-focus")}},{key:"onMultiInputBlur",value:function(e){this.onInputBlur(e),r.DomHandler.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