"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/api"),r=require("primereact/overlayservice"),i=require("primereact/tree"),l=require("primereact/csstransition"),o=require("primereact/portal"),s=require("primereact/ripple");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var c=a(e),p=a(n);function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var n=0;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 l,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,l=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw l}}}}function N(e,t){if(e){if("string"==typeof e)return x(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)?x(e,t):void 0}}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n0){var t,n=L({},this.state.expandedKeys||{}),r=w(e);try{for(r.s();!(t=r.n()).done;){n[t.value]=!0}}catch(e){r.e(e)}finally{r.f()}this.setState({expandedKeys:n})}}},{key:"componentDidMount",value:function(){this.updateTreeState()}},{key:"componentDidUpdate",value:function(e,t){this.state.overlayVisible&&((this.props.filter||t.expandedKeys!==this.state.expandedKeys)&&this.alignOverlay(),e.value!==this.props.value&&(this.selfChange||this.updateTreeState(),this.scrollInView(),this.selfChange=!1)),e.options!==this.props.options&&this.updateTreeState()}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),t.ZIndexUtils.clear(this.overlayRef.current)}},{key:"renderKeyboardHelper",value:function(){var e=this;return c.default.createElement("div",{className:"p-hidden-accessible"},c.default.createElement("input",{ref:function(t){return e.focusInput=t},role:"listbox",id:this.props.inputId,type:"text",readOnly:!0,"aria-haspopup":"true","aria-expanded":this.state.overlayVisible,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.isValueEmpty(),r=t.classNames("p-treeselect-label",{"p-placeholder":this.getLabel()===this.props.placeholder,"p-treeselect-label-empty":!this.props.placeholder&&n}),i=null;if(this.props.valueTemplate)i=t.ObjectUtils.getJSXElement(this.props.valueTemplate,e,this.props);else if("comma"===this.props.display)i=this.getLabel()||"empty";else if("chip"===this.props.display){var l=this.getSelectedNodes();i=c.default.createElement(c.default.Fragment,null,l&&l.map((function(e,t){return c.default.createElement("div",{className:"p-treeselect-token",key:"".concat(e.key,"_").concat(t)},c.default.createElement("span",{className:"p-treeselect-token-label"},e.label))})),n&&(this.props.placeholder||"empty"))}return c.default.createElement("div",{className:"p-treeselect-label-container"},c.default.createElement("div",{className:r},i))}},{key:"renderDropdownIcon",value:function(){var e=this,n=t.classNames("p-treeselect-trigger-icon p-clickable",this.props.dropdownIcon);return c.default.createElement("div",{ref:function(t){return e.trigger=t},className:"p-treeselect-trigger",role:"button","aria-haspopup":"listbox","aria-expanded":this.state.overlayVisible},c.default.createElement("span",{className:n}))}},{key:"renderContent",value:function(){var e=this.getFilterValue();return c.default.createElement(c.default.Fragment,null,c.default.createElement(i.Tree,{value:this.props.options,selectionMode:this.props.selectionMode,selectionKeys:this.props.value,metaKeySelection:this.props.metaKeySelection,onSelectionChange:this.onSelectionChange,onSelect:this.onNodeSelect,onUnselect:this.onNodeUnselect,expandedKeys:this.state.expandedKeys,onToggle:this.onNodeToggle,onExpand:this.props.onNodeExpand,onCollapse:this.props.onNodeCollapse,filter:this.props.filter,filterValue:e,filterBy:this.props.filterBy,filterMode:this.props.filterMode,filterPlaceholder:this.props.filterPlaceholder,filterLocale:this.props.filterLocale,showHeader:!1,onFilterValueChange:this.onFilterValueChange}),this.hasNoOptions()&&c.default.createElement("div",{className:"p-treeselect-empty-message"},this.props.emptyMessage||n.localeOption("emptyMessage")))}},{key:"renderFilterElement",value:function(){var e=this;if(this.props.filter){var n=this.getFilterValue();return n=t.ObjectUtils.isNotEmpty(n)?n:"",c.default.createElement("div",{className:"p-treeselect-filter-container"},c.default.createElement("input",{ref:function(t){return e.filterInput=t},type:"text",value:n,autoComplete:"off",className:"p-treeselect-filter p-inputtext p-component",placeholder:this.props.filterPlaceholder,onKeyDown:this.onFilterInputKeyDown,onChange:this.onFilterInputChange,disabled:this.props.disabled}),c.default.createElement("span",{className:"p-treeselect-filter-icon pi pi-search"}))}return null}},{key:"renderHeader",value:function(){var e=this.renderFilterElement(),n=c.default.createElement("button",{type:"button",className:"p-treeselect-close p-link",onClick:this.hide},c.default.createElement("span",{className:"p-treeselect-close-icon pi pi-times"}),c.default.createElement(s.Ripple,null)),r=c.default.createElement("div",{className:"p-treeselect-header"},e,n);return this.props.header?t.ObjectUtils.getJSXElement(this.props.header,{className:"p-treeselect-header",filterElement:e,closeElement:n,closeElementClassName:"p-treeselect-close p-link",closeIconClassName:"p-treeselect-close-icon pi pi-times",onCloseClick:this.hide,element:r,props:this.props}):r}},{key:"render",value:function(){var e=this,n=t.classNames("p-treeselect p-component p-inputwrapper",{"p-treeselect-chip":"chip"===this.props.display,"p-disabled":this.props.disabled,"p-focus":this.state.focused,"p-inputwrapper-filled":!this.isValueEmpty(),"p-inputwrapper-focus":this.state.focused||this.state.overlayVisible},this.props.className),r=this.getSelectedNodes(),i=this.renderKeyboardHelper(),l=this.renderLabel(r),o=this.renderDropdownIcon(),s=this.renderContent(),a=this.renderHeader(),p=t.ObjectUtils.getJSXElement(this.props.footer,this.props);return c.default.createElement("div",{id:this.props.id,ref:function(t){return e.container=t},className:n,style:this.props.style,onClick:this.onClick},i,l,o,c.default.createElement(C,{ref:this.overlayRef,appendTo:this.props.appendTo,panelStyle:this.props.panelStyle,panelClassName:this.props.panelClassName,scrollHeight:this.props.scrollHeight,onClick:this.onOverlayClick,header:a,footer:p,transitionOptions:this.props.transitionOptions,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited},s))}}]),y}();k(j,"defaultProps",{id:null,value:null,name:null,style:null,className:null,disabled:!1,options:null,scrollHeight:"400px",placeholder:null,tabIndex:null,inputId:null,ariaLabel:null,ariaLabelledBy:null,selectionMode:"single",panelStyle:null,panelClassName:null,appendTo:null,emptyMessage:null,display:"comma",metaKeySelection:!0,valueTemplate:null,panelHeaderTemplate:null,panelFooterTemplate:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",filter:!1,filterValue:null,filterBy:"label",filterMode:"lenient",filterPlaceholder:null,filterLocale:void 0,filterInputAutoFocus:!0,resetFilterOnHide:!1,onShow:null,onHide:null,onChange:null,onNodeSelect:null,onNodeUnselect:null,onNodeExpand:null,onNodeCollapse:null,onFilterValueChange:null}),exports.TreeSelect=j;