import e,{Component as t,createRef as n}from"react";import{classNames as r,ObjectUtils as i,DomHandler as o,ZIndexUtils as l,ConnectedOverlayScrollHandler as s}from"primereact/utils";import a,{localeOption as p}from"primereact/api";import{OverlayService as c}from"primereact/overlayservice";import{Tree as u}from"primereact/tree";import{CSSTransition as h}from"primereact/csstransition";import{Portal as d}from"primereact/portal";import{Ripple as f}from"primereact/ripple";function y(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function v(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 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 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);n0){var t,n=j({},this.state.expandedKeys||{}),r=L(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),l.clear(this.overlayRef.current)}},{key:"renderKeyboardHelper",value:function(){var t=this;return e.createElement("div",{className:"p-hidden-accessible"},e.createElement("input",{ref:function(e){return t.focusInput=e},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(t){var n=this.isValueEmpty(),o=r("p-treeselect-label",{"p-placeholder":this.getLabel()===this.props.placeholder,"p-treeselect-label-empty":!this.props.placeholder&&n}),l=null;if(this.props.valueTemplate)l=i.getJSXElement(this.props.valueTemplate,t,this.props);else if("comma"===this.props.display)l=this.getLabel()||"empty";else if("chip"===this.props.display){var s=this.getSelectedNodes();l=e.createElement(e.Fragment,null,s&&s.map((function(t,n){return e.createElement("div",{className:"p-treeselect-token",key:"".concat(t.key,"_").concat(n)},e.createElement("span",{className:"p-treeselect-token-label"},t.label))})),n&&(this.props.placeholder||"empty"))}return e.createElement("div",{className:"p-treeselect-label-container"},e.createElement("div",{className:o},l))}},{key:"renderDropdownIcon",value:function(){var t=this,n=r("p-treeselect-trigger-icon p-clickable",this.props.dropdownIcon);return e.createElement("div",{ref:function(e){return t.trigger=e},className:"p-treeselect-trigger",role:"button","aria-haspopup":"listbox","aria-expanded":this.state.overlayVisible},e.createElement("span",{className:n}))}},{key:"renderContent",value:function(){var t=this.getFilterValue();return e.createElement(e.Fragment,null,e.createElement(u,{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:t,filterBy:this.props.filterBy,filterMode:this.props.filterMode,filterPlaceholder:this.props.filterPlaceholder,filterLocale:this.props.filterLocale,showHeader:!1,onFilterValueChange:this.onFilterValueChange}),this.hasNoOptions()&&e.createElement("div",{className:"p-treeselect-empty-message"},this.props.emptyMessage||p("emptyMessage")))}},{key:"renderFilterElement",value:function(){var t=this;if(this.props.filter){var n=this.getFilterValue();return n=i.isNotEmpty(n)?n:"",e.createElement("div",{className:"p-treeselect-filter-container"},e.createElement("input",{ref:function(e){return t.filterInput=e},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}),e.createElement("span",{className:"p-treeselect-filter-icon pi pi-search"}))}return null}},{key:"renderHeader",value:function(){var t=this.renderFilterElement(),n=e.createElement("button",{type:"button",className:"p-treeselect-close p-link",onClick:this.hide},e.createElement("span",{className:"p-treeselect-close-icon pi pi-times"}),e.createElement(f,null)),r=e.createElement("div",{className:"p-treeselect-header"},t,n);return this.props.header?i.getJSXElement(this.props.header,{className:"p-treeselect-header",filterElement:t,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 t=this,n=r("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),o=this.getSelectedNodes(),l=this.renderKeyboardHelper(),s=this.renderLabel(o),a=this.renderDropdownIcon(),p=this.renderContent(),c=this.renderHeader(),u=i.getJSXElement(this.props.footer,this.props);return e.createElement("div",{id:this.props.id,ref:function(e){return t.container=e},className:n,style:this.props.style,onClick:this.onClick},l,s,a,e.createElement(I,{ref:this.overlayRef,appendTo:this.props.appendTo,panelStyle:this.props.panelStyle,panelClassName:this.props.panelClassName,scrollHeight:this.props.scrollHeight,onClick:this.onOverlayClick,header:c,footer:u,transitionOptions:this.props.transitionOptions,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited},p))}}]),E}();w(D,"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});export{D as TreeSelect};