"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),n=require("primereact/componentbase"),r=require("primereact/hooks"),o=require("primereact/icons/chevrondown"),l=require("primereact/icons/chevronup"),i=require("primereact/icons/spinner"),a=require("primereact/icons/times"),c=require("primereact/overlayservice"),u=require("primereact/tooltip"),s=require("primereact/utils"),p=require("primereact/csstransition"),d=require("primereact/icons/search"),f=require("primereact/portal"),m=require("primereact/virtualscroller"),v=require("primereact/ripple"),b=require("primereact/icons/check"),g=require("primereact/iconbase");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function y(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var w=y(e),O=h(t);function I(){return I=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var n=0,r=Array(t);n2&&void 0!==arguments[2]?arguments[2]:{},o={height:r.props?r.props.itemSize:void 0};if(o=A(A({},o),t.style),t.group&&e.optionGroupLabel){var l=e.optionGroupLabel,i=e.optionGroupTemplate?s.ObjectUtils.getJSXElement(e.optionGroupTemplate,t,n):e.getOptionGroupLabel(t),a=n+"_"+e.getOptionGroupRenderKey(t),c=v({className:g("itemGroup",{optionGroupLabel:l}),style:o,"data-p-highlight":e.selected},D("itemGroup")),u=v({className:g("itemGroupLabel")},D("itemGroupLabel"));return w.createElement("li",I({key:a},c),w.createElement("span",u,i))}var p=e.getOptionRenderKey(t)+"_"+n,d=e.getOptionLabel(t),f=e.isOptionDisabled(t);return w.createElement(M,{key:p,label:d,index:n,focusedOptionIndex:e.focusedOptionIndex,option:t,ariaSetSize:x,onInputKeyDown:e.onInputKeyDown,style:o,template:e.itemTemplate,selected:e.isSelected(t),highlightOnSelect:e.highlightOnSelect,disabled:f,onClick:e.onOptionClick,onMouseMove:C,ptm:b,cx:g,checkmark:e.checkmark})},U=function(){if(e.showFilterClear&&e.filterValue){var n=t.localeOption("clear"),r=v({className:g("filterClearIcon"),"aria-label":n,onClick:function(){return e.onFilterClearIconClick((function(){return s.DomHandler.focus(O.current)}))}},D("filterClearIcon"));return s.IconUtils.getJSXIcon(e.filterClearIcon||w.createElement(a.TimesIcon,r),A({},r),{props:e})}return null},T=function(){if(e.filter){var t=U(),n=v({className:g("filterIcon")},D("filterIcon")),r=s.IconUtils.getJSXIcon(e.filterIcon||w.createElement(d.SearchIcon,n),A({},n),{props:e}),o=v({className:g("filterContainer",{clearIcon:t})},D("filterContainer")),l=v({ref:O,type:"text",autoComplete:"off",className:g("filterInput",{context:y}),placeholder:e.filterPlaceholder,onKeyDown:e.onFilterInputKeyDown,onChange:function(e){return N(e)},value:e.filterValue},D("filterInput")),i=w.createElement("div",o,w.createElement("input",l),t,r);if(e.filterTemplate){var a={className:s.classNames("p-dropdown-filter-container",{"p-dropdown-clearable-filter":!!t}),element:i,filterOptions:S,filterInputKeyDown:e.onFilterInputKeyDown,filterInputChange:N,filterIconClassName:"p-dropdown-filter-icon",clearIcon:t,props:e};i=s.ObjectUtils.getJSXElement(e.filterTemplate,a)}var c=v({className:g("header")},D("header"));return w.createElement("div",c,i)}return null},R=function(){if(e.virtualScrollerOptions){var n=A(A({},e.virtualScrollerOptions),{style:A(A({},e.virtualScrollerOptions.style),{height:e.scrollHeight}),className:s.classNames("p-dropdown-items-wrapper",e.virtualScrollerOptions.className),items:e.visibleOptions,autoSize:!0,onLazyLoad:function(t){return e.virtualScrollerOptions.onLazyLoad(A(A({},t),{filter:e.filterValue}))},itemTemplate:function(e,t){return e&&P(e,t.index,t)},contentTemplate:function(n){var r=n.children||[],o=E||0===(null==r?void 0:r.length)?L(e.hasFilter?e.emptyFilterMessage:e.emptyMessage):r,l=v({ref:n.contentRef,style:n.style,className:s.classNames(n.className,g("list",{virtualScrollerProps:e.virtualScrollerOptions})),role:"listbox","aria-label":t.ariaLabel("listLabel")},D("list"));return w.createElement("ul",l,o)}});return w.createElement(m.VirtualScroller,I({ref:e.virtualScrollerRef},n,{pt:b("virtualScroller")}))}var r=s.ObjectUtils.isNotEmpty(e.visibleOptions)?e.visibleOptions.map(P):e.hasFilter?L(e.emptyFilterMessage,!0):L(e.emptyMessage),o=v({className:g("wrapper"),style:h("wrapper")},D("wrapper")),l=v({className:g("list"),role:"listbox","aria-label":t.ariaLabel("listLabel")},D("list"));return w.createElement("div",o,w.createElement("ul",l,r))},H=(o=T(),l=R(),i=k(),c=v({className:s.classNames(e.panelClassName,g("panel",{context:y})),style:h("panel"),onClick:e.onClick,"data-pr-is-overlay":!0},D("panel")),u=v({classNames:g("transition"),in:e.in,timeout:{enter:120,exit:100},options:e.transitionOptions,unmountOnExit:!0,onEnter:j,onEntered:F,onExit:e.onExit,onExited:e.onExited},D("transition")),w.createElement(p.CSSTransition,I({nodeRef:n},u),w.createElement("div",I({ref:n},c),e.firstFocusableElement,o,l,i,e.lastFocusableElement)));return w.createElement(f.Portal,{element:H,appendTo:e.appendTo})})));function K(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=q(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=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 l,i=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){a=!0,l=e},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw l}}}}function q(e,t){if(e){if("string"==typeof e)return V(e,t);var n={}.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)?V(e,t):void 0}}function V(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n2&&void 0!==arguments[2])||arguments[2];He({originalEvent:e,option:t}),n&&(_e(),s.DomHandler.focus(V.current))},ue=function(e){if(m.disabled)e.preventDefault();else{switch(s.DomHandler.isAndroid()?e.key:e.code){case"ArrowDown":Oe(e);break;case"ArrowUp":Ie(e);break;case"ArrowLeft":case"ArrowRight":Ee(e,m.editable);break;case"Home":xe(e);break;case"End":Se(e);break;case"PageDown":je(e);break;case"PageUp":De(e);break;case"Space":Fe(e,m.editable);break;case"NumpadEnter":case"Enter":Ne(e);break;case"Escape":ke(e);break;case"Tab":Ce(e);break;case"Backspace":Le(e,m.editable);break;case"ShiftLeft":case"ShiftRight":break;default:!(e.metaKey||e.ctrlKey||e.altKey)&&s.ObjectUtils.isPrintableCharacter(e.key)&&(!C&&!m.editable&&Ve(),!m.editable&&be(e,e.key))}U.current=!1}},se=function(e){var t;return pe(e)&&(null===(t=Xe(e))||void 0===t?void 0:t.toLocaleLowerCase(m.filterLocale).startsWith(J.current.toLocaleLowerCase(m.filterLocale)))},pe=function(e){return s.ObjectUtils.isNotEmpty(e)&&!($e(e)||We(e))},de=function(){return s.ObjectUtils.isNotEmpty(m.value)},fe=function(e){return pe(e)&&qe(e)},me=function(){return de?it.findIndex((function(e){return fe(e)})):-1},ve=function(){var e=me();return e<0?ge():e},be=function(e,t){J.current=(J.current||"")+t;var n=-1,r=!1;return s.ObjectUtils.isNotEmpty(J.current)&&(-1!==(n=-1!==F?-1===(n=it.slice(F).findIndex((function(e){return se(e)})))?it.slice(0,F).findIndex((function(e){return se(e)})):n+F:it.findIndex((function(e){return se(e)})))&&(r=!0),-1===n&&-1===F&&(n=ve()),-1!==n&&ye(e,n)),z.current&&clearTimeout(z.current),z.current=setTimeout((function(){J.current="",z.current=null}),500),r},ge=function(){return it.findIndex((function(e){return pe(e)}))},he=function(){return s.ObjectUtils.findLastIndex(it,(function(e){return pe(e)}))},ye=function(e,t){F!==t&&(N(t),we(t),m.selectOnFocus&&ce(e,it[t],!1))},we=function(e){var t=s.DomHandler.findSingle(M.current,'li[id="dropdownItem_'.concat(e,'"]'));t&&t.focus()},Oe=function(e){if(C){var t=-1!==F?(r=(n=F)-1?r+n+1:n:U.current?ge():ve();ye(e,t)}else Ve(),m.editable&&ye(e,me());var n,r;e.preventDefault()},Ie=function(e){var t,n,r;if(e.altKey&&!(arguments.length>1&&void 0!==arguments[1]&&arguments[1]))-1!==F&&ce(e,it[F]),state.overlayVisible&&_e(),e.preventDefault();else{var o=-1!==F?(r=(n=F)>0?s.ObjectUtils.findLastIndex(it.slice(0,n),(function(e){return pe(e)})):-1)>-1?r:n:U.current?he():(t=me())<0?he():t;ye(e,o),!C&&Ve(),e.preventDefault()}},Ee=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&N(-1)},xe=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?(e.currentTarget.setSelectionRange(0,0),N(-1)):(ye(e,ge()),!C&&Ve()),e.preventDefault()},Se=function(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1]){var t=e.currentTarget,n=t.value.length;t.setSelectionRange(n,n),N(-1)}else ye(e,he()),!C&&Ve();e.preventDefault()},De=function(e){e.preventDefault()},je=function(e){e.preventDefault()},Fe=function(e){!(arguments.length>1&&void 0!==arguments[1]&&arguments[1])&&Ne(e)},Ne=function(e){if(e.preventDefault(),C){if(-1===F)return;var t=it[F],n=Ze(t);if(null==n||null==n)return _e(),Re(),void Je(at);ce(e,t)}else N(-1),Oe(e)},ke=function(e){C&&_e(),e.preventDefault()},Ce=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]||(!C||s.DomHandler.getFocusableElements(M.current,':not([data-p-hidden-focusable="true"])').length>0?(-1!==F&&ce(e,it[F]),C&&_e()):(s.DomHandler.focus(H.current),e.preventDefault()))},Le=function(e){e&&(arguments.length>1&&void 0!==arguments[1]&&arguments[1])&&!C&&Ve()},Pe=function(e,t){if(!t||null==e||!e.length)return-1;var n=t.toLocaleLowerCase(),r=e.findIndex((function(e){return Xe(e).toLocaleLowerCase()===n}));return-1!==r?r:e.findIndex((function(e){return Xe(e).toLocaleLowerCase().startsWith(n)}))},Ue=function(e){!C&&Ve();var t=null;e.target.value&&it&&(t=Pe(it,e.target.value)),N(t),m.onChange&&m.onChange({originalEvent:e.originalEvent,value:e.target.value,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:m.name,id:m.id,value:e.target.value}})},Te=function(e){S(!0),_e(),m.onFocus&&m.onFocus(e)},Re=function(e){h(""),m.onFilter&&m.onFilter({filter:""}),e&&e()},Me=function(e){m.onChange&&m.onChange({originalEvent:e,value:void 0,stopPropagation:function(){null==e||e.stopPropagation()},preventDefault:function(){null==e||e.preventDefault()},target:{name:m.name,id:m.id,value:void 0}}),m.filter&&Re(),Je(),N(-1)},He=function(e){if(at!==e.option){Je(e.option),N(-1);var t=Ze(e.option),n=Ke(e.option,it);m.onChange&&m.onChange({originalEvent:e.originalEvent,value:t,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:m.name,id:m.id,value:t}}),ye(e.originalEvent,n)}},Ae=function(e){if(e=e||it){if(!m.optionGroupLabel)return Ke(m.value,e);for(var t=0;t=0)&&ze()}),[C,m.value,F]),r.useUpdateEffect((function(){C&&g&&m.filter&&Be()}),[C,g,m.filter]),r.useUpdateEffect((function(){_.current&&_.current.scrollInView(0)}),[g]),r.useUpdateEffect((function(){Qe(),q.current&&(q.current.selectedIndex=1)})),r.useUnmountEffect((function(){s.ZIndexUtils.clear(M.current)}));var et,tt,nt,rt,ot,lt=function(e){"Enter"!==e.key&&"Space"!==e.code||(Me(e),e.preventDefault())},it=function(){var e=m.optionGroupLabel?oe(m.options):m.options;if(Z&&!X){var n=g.trim().toLocaleLowerCase(m.filterLocale),r=m.filterBy?m.filterBy.split(","):[m.optionLabel||"label"];if(m.optionGroupLabel){var o,l=[],i=K(m.options);try{for(i.s();!(o=i.n()).done;){var a=o.value,c=t.FilterService.filter(Ye(a),r,n,m.filterMatchMode,m.filterLocale);c&&c.length&&l.push(B(B({},a),D({},"".concat(m.optionGroupChildren),c)))}}catch(e){i.e(e)}finally{i.f()}return oe(l)}return t.FilterService.filter(e,r,n,m.filterMatchMode,m.filterLocale)}return e}(),at=-1!==(et=Ae(m.options))?m.optionGroupLabel?Ye(m.options[et.group])[et.option]:m.options[et]:null,ct=s.ObjectUtils.isNotEmpty(m.tooltip),ut=T.getOtherProps(m),st=s.ObjectUtils.reduceKeys(ut,s.DomHandler.ARIA_PROPS),pt=function(){var e={value:"",label:m.placeholder};if(at){var t=Ze(at);e={value:"object"===E(t)?m.options.findIndex((function(e){return e===t})):t,label:Xe(at)}}var n=d({className:"p-hidden-accessible p-dropdown-hidden-select"},Y("hiddenSelectedMessage")),r=d({ref:q,required:m.required,defaultValue:e.value,name:m.name,tabIndex:-1},Y("select")),o=d({value:e.value},Y("option"));return w.createElement("div",n,w.createElement("select",r,w.createElement("option",o,e.label)))}(),dt=function(){var e=s.ObjectUtils.isNotEmpty(at)?Xe(at):null;m.editable&&(e=e||m.value||"");var t=d({className:"p-hidden-accessible"},Y("hiddenSelectedMessage")),n=d(B({ref:V,id:m.inputId,defaultValue:e,type:"text",readOnly:!0,"aria-haspopup":"listbox",onFocus:ie,onBlur:ae,onKeyDown:ue,disabled:m.disabled,tabIndex:m.disabled?-1:m.tabIndex||0},st),Y("input"));return w.createElement("div",t,w.createElement("input",n))}(),ft=function(){var e=s.ObjectUtils.isNotEmpty(at)?Xe(at):null;if(m.editable){var t=d(B({ref:q,type:"text",defaultValue:e||m.value||"",className:Q("input",{label:e}),disabled:m.disabled,placeholder:m.placeholder,maxLength:m.maxLength,onInput:Ue,onFocus:Te,onKeyDown:ue,onBlur:ae,tabIndex:m.disabled?-1:m.tabIndex||0,"aria-haspopup":"listbox"},st),Y("input"));return w.createElement("input",t)}var n=m.valueTemplate?s.ObjectUtils.getJSXElement(m.valueTemplate,at,m):e||m.placeholder||m.emptyMessage||w.createElement(w.Fragment,null," "),r=d({ref:q,className:Q("input",{label:e}),tabIndex:"-1"},Y("input"));return w.createElement("span",r,n)}(),mt=m.loading?(tt=d({className:Q("loadingIcon"),"data-pr-overlay-visible":C},Y("loadingIcon")),nt=s.IconUtils.getJSXIcon(m.loadingIcon||w.createElement(i.SpinnerIcon,{spin:!0}),B({},tt),{props:m}),rt=m.placeholder||m.ariaLabel,ot=d({className:Q("trigger"),role:"button","aria-haspopup":"listbox","aria-expanded":C,"aria-label":rt},Y("trigger")),w.createElement("div",ot,nt)):function(){var e=d({className:Q("dropdownIcon"),"data-pr-overlay-visible":C},Y("dropdownIcon")),t=s.IconUtils.getJSXIcon(C?m.collapseIcon||w.createElement(l.ChevronUpIcon,e):m.dropdownIcon||w.createElement(o.ChevronDownIcon,e),B({},e),{props:m}),n=m.placeholder||m.ariaLabel,r=d({className:Q("trigger"),role:"button","aria-haspopup":"listbox","aria-expanded":C,"aria-label":n},Y("trigger"));return w.createElement("div",r,t)}(),vt=function(){if(null!=m.value&&m.showClear&&!m.disabled&&!s.ObjectUtils.isEmpty(m.options)){var e=d({className:Q("clearIcon"),onPointerUp:Me,tabIndex:m.editable?-1:m.tabIndex||"0",onKeyDown:lt,"aria-label":t.localeOption("clear")},Y("clearIcon"));return s.IconUtils.getJSXIcon(m.clearIcon||w.createElement(a.TimesIcon,e),B({},e),{props:m})}return null}(),bt=d({id:m.id,ref:R,className:s.classNames(m.className,Q("root",{context:f,focusedState:x,overlayVisibleState:C})),style:m.style,onClick:function(e){return t=e,void(m.disabled||m.loading||(m.onClick&&m.onClick(t),t.defaultPrevented||le(t)||"INPUT"===t.target.tagName||(M.current&&M.current&&M.current.contains(t.target)||(s.DomHandler.focus(V.current),C?_e():Ve()),t.preventDefault(),U.current=!0)));var t},onMouseDown:m.onMouseDown,onContextMenu:m.onContextMenu,onFocus:function(){m.editable&&!C&&!1===U.current&&s.DomHandler.focus(q.current)},"data-p-disabled":m.disabled,"data-p-focus":x,"aria-activedescendant":x?"dropdownItem_".concat(F):void 0},ut,Y("root")),gt=d({ref:H,role:"presentation",className:"p-hidden-accessible p-hidden-focusable",tabIndex:"0",onFocus:function(e){var t=e.relatedTarget===V.current?s.DomHandler.getFirstFocusableElement(M.current,':not([data-p-hidden-focusable="true"])'):V.current;s.DomHandler.focus(t)},"data-p-hidden-accessible":!0,"data-p-hidden-focusable":!0},Y("hiddenFirstFocusableEl")),ht=d({ref:A,role:"presentation",className:"p-hidden-accessible p-hidden-focusable",tabIndex:"0",onFocus:function(e){var t=e.relatedTarget===V.current?s.DomHandler.getLastFocusableElement(M.current,':not([data-p-hidden-focusable="true"])'):V.current;s.DomHandler.focus(t)},"data-p-hidden-accessible":!0,"data-p-hidden-focusable":!0},Y("hiddenLastFocusableEl"));return w.createElement(w.Fragment,null,w.createElement("div",bt,dt,pt,ft,vt,mt,w.createElement(G,I({hostName:"Dropdown",ref:M,visibleOptions:it,virtualScrollerRef:_},m,{appendTo:W,cx:Q,filterValue:b,focusedOptionIndex:F,getOptionGroupChildren:Ye,getOptionGroupLabel:function(e){return s.ObjectUtils.resolveFieldData(e,m.optionGroupLabel)},getOptionGroupRenderKey:function(e){return s.ObjectUtils.resolveFieldData(e,m.optionGroupLabel)},getOptionLabel:Xe,getOptionRenderKey:function(e){return m.dataKey?s.ObjectUtils.resolveFieldData(e,m.dataKey):Xe(e)},getSelectedOptionIndex:Ae,hasFilter:Z,in:C,isOptionDisabled:$e,isSelected:qe,onOverlayHide:_e,onClick:function(e){c.OverlayService.emit("overlay-click",{originalEvent:e,target:R.current})},onEnter:function(e){s.ZIndexUtils.set("overlay",M.current,f&&f.autoZIndex||O.default.autoZIndex,f&&f.zIndex.overlay||O.default.zIndex.overlay),s.DomHandler.addStyles(M.current,{position:"absolute",top:"0",left:"0"}),Be(),e&&e()},onEntered:function(e){e&&e(),ne(),m.onShow&&m.onShow()},onExit:function(){re()},onExited:function(){m.filter&&m.resetFilterOnHide&&Re(),s.ZIndexUtils.clear(M.current),m.onHide&&m.onHide()},onFilterClearIconClick:function(e){Re(e)},onFilterInputChange:function(e){var t=e.target.value;h(t),m.onFilter&&m.onFilter({originalEvent:e,filter:t})},onFilterInputKeyDown:function(e){switch(e.code){case"ArrowDown":Oe(e);break;case"ArrowUp":Ie(e);break;case"ArrowLeft":case"ArrowRight":Ee(e,!0);break;case"Enter":case"NumpadEnter":Ne(e),e.preventDefault();break;case"Escape":ke(e)}},onOptionClick:function(e){e.option.disabled||(He(e),s.DomHandler.focus(V.current)),_e()},onInputKeyDown:ue,ptm:Y,resetFilter:Re,changeFocusedOptionIndex:ye,firstFocusableElement:w.createElement("span",gt),lastFocusableElement:w.createElement("span",ht),sx:ee}))),ct&&w.createElement(u.Tooltip,I({target:R,content:m.tooltip,pt:Y("tooltip")},m.tooltipOptions)))})));z.displayName="Dropdown",exports.Dropdown=z;