import e,{Component as t}from"react";import{DomHandler as n,ObjectUtils as o,classNames as r}from"primereact/utils";import{Ripple as i}from"primereact/ripple";function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,s=!0,p=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){p=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(p)throw i}}}}function D(e,t){if(e){if("string"==typeof e)return C(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)?C(e,t):void 0}}function C(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);n0&&r!==this.props.node.children.length?o[this.props.node.key]={checked:!1,partialChecked:!0}:delete o[this.props.node.key]),this.props.propagateSelectionUp&&this.props.onPropagateUp&&this.props.onPropagateUp(e)}},{key:"propagateDown",value:function(e,t,n){if(t?n[e.key]={checked:!0,partialChecked:!1}:delete n[e.key],e.children&&e.children.length)for(var o=0;ot.left+t.width||e.nativeEvent.x=Math.floor(t.top+t.height)||e.nativeEvent.y=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:r}}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 i,s=!0,p=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){p=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(p)throw i}}}}function T(e,t){if(e){if("string"==typeof e)return M(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)?M(e,t):void 0}}function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=new Array(t);ne.index?e.index:e.index-1:e.index;i?i.children.splice(l,0,s):t.splice(l,0,s)}else i?i.children.push(s):t.push(s);this.props.onDragDrop&&this.props.onDragDrop({originalEvent:e.originalEvent,value:t,dragNode:s,dropNode:i,dropIndex:e.index})}}},{key:"validateDrop",value:function(e,t){return!!e&&(e!==t&&0!==t.indexOf(e))}},{key:"validateDropNode",value:function(e,t){return!!this.validateDrop(e,t)&&!(e.indexOf("-")>0&&e.substring(0,e.lastIndexOf("-"))===t)}},{key:"validateDropPoint",value:function(e){return!!this.validateDrop(this.dragState.path,e.path)&&(-1!==e.position||!this.areSiblings(this.dragState.path,e.path)||this.dragState.index+1!==e.index)}},{key:"areSiblings",value:function(e,t){return 1===e.length&&1===t.length||e.substring(0,e.lastIndexOf("-"))===t.substring(0,t.lastIndexOf("-"))}},{key:"findNode",value:function(e,t){if(0===t.length)return null;var n=parseInt(t[0],10),o=e.children?e.children[n]:e[n];return 1===t.length?o:(t.shift(),this.findNode(o,t))}},{key:"isNodeLeaf",value:function(e){return!1!==e.leaf&&!(e.children&&e.children.length)}},{key:"onFilterInputKeyDown",value:function(e){13===e.which&&e.preventDefault()}},{key:"onFilterInputChange",value:function(e){this.filterChanged=!0;var t=e.target.value;this.props.onFilterValueChange?this.props.onFilterValueChange({originalEvent:e,value:t}):this.setState({filterValue:t})}},{key:"filter",value:function(e){this.setState({filterValue:o.isNotEmpty(e)?e:""},this._filter)}},{key:"_filter",value:function(){if(this.filterChanged){var e=this.getFilterValue();if(o.isEmpty(e))this.filteredNodes=this.props.value;else{this.filteredNodes=[];var t,n=this.props.filterBy.split(","),r=e.toLocaleLowerCase(this.props.filterLocale),i="strict"===this.props.filterMode,s=K(this.props.value);try{for(s.s();!(t=s.n()).done;){var p=P({},t.value),l={searchFields:n,filterText:r,isStrictMode:i};(i&&(this.findFilteredNodes(p,l)||this.isFilterMatched(p,l))||!i&&(this.isFilterMatched(p,l)||this.findFilteredNodes(p,l)))&&this.filteredNodes.push(p)}}catch(e){s.e(e)}finally{s.f()}}this.filterChanged=!1}}},{key:"findFilteredNodes",value:function(e,t){if(e){var n=!1;if(e.children){var o=p(c=e.children)||l(c)||a(c)||d();e.children=[];var r,i=K(o);try{for(i.s();!(r=i.n()).done;){var s=P({},r.value);this.isFilterMatched(s,t)&&(n=!0,e.children.push(s))}}catch(e){i.e(e)}finally{i.f()}}if(n)return e.expanded=!0,!0}var c}},{key:"isFilterMatched",value:function(e,t){var n,r=t.searchFields,i=t.filterText,s=t.isStrictMode,p=!1,l=K(r);try{for(l.s();!(n=l.n()).done;){String(o.resolveFieldData(e,n.value)).toLocaleLowerCase(this.props.filterLocale).indexOf(i)>-1&&(p=!0)}}catch(e){l.e(e)}finally{l.f()}return(!p||s&&!this.isNodeLeaf(e))&&(p=this.findFilteredNodes(e,{searchFields:r,filterText:i,isStrictMode:s})||p),p}},{key:"renderRootChild",value:function(t,n,o){return e.createElement(O,{key:t.key||t.label,node:t,index:n,last:o,path:String(n),disabled:this.props.disabled,selectionMode:this.props.selectionMode,selectionKeys:this.props.selectionKeys,onSelectionChange:this.props.onSelectionChange,metaKeySelection:this.props.metaKeySelection,contextMenuSelectionKey:this.props.contextMenuSelectionKey,onContextMenuSelectionChange:this.props.onContextMenuSelectionChange,onContextMenu:this.props.onContextMenu,propagateSelectionDown:this.props.propagateSelectionDown,propagateSelectionUp:this.props.propagateSelectionUp,onExpand:this.props.onExpand,onCollapse:this.props.onCollapse,onSelect:this.props.onSelect,onUnselect:this.props.onUnselect,expandedKeys:this.getExpandedKeys(),onToggle:this.onToggle,nodeTemplate:this.props.nodeTemplate,togglerTemplate:this.props.togglerTemplate,isNodeLeaf:this.isNodeLeaf,dragdropScope:this.props.dragdropScope,onDragStart:this.onDragStart,onDragEnd:this.onDragEnd,onDrop:this.onDrop,onDropPoint:this.onDropPoint,onNodeClick:this.props.onNodeClick,onNodeDoubleClick:this.props.onNodeDoubleClick})}},{key:"renderRootChildren",value:function(){var e=this;this.props.filter&&(this.filterChanged=!0,this._filter());var t=this.getRootNode();return t.map((function(n,o){return e.renderRootChild(n,o,o===t.length-1)}))}},{key:"renderModel",value:function(){if(this.props.value){var t=this.renderRootChildren(),n=r("p-tree-container",this.props.contentClassName);return e.createElement("ul",{className:n,role:"tree","aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy,style:this.props.contentStyle},t)}return null}},{key:"renderLoader",value:function(){if(this.props.loading){var t=r("p-tree-loading-icon pi-spin",this.props.loadingIcon);return e.createElement("div",{className:"p-tree-loading-overlay p-component-overlay"},e.createElement("i",{className:t}))}return null}},{key:"renderFilter",value:function(){if(this.props.filter){var t=this.getFilterValue();return t=o.isNotEmpty(t)?t:"",e.createElement("div",{className:"p-tree-filter-container"},e.createElement("input",{type:"text",value:t,autoComplete:"off",className:"p-tree-filter p-inputtext p-component",placeholder:this.props.filterPlaceholder,onKeyDown:this.onFilterInputKeyDown,onChange:this.onFilterInputChange,disabled:this.props.disabled}),e.createElement("span",{className:"p-tree-filter-icon pi pi-search"}))}return null}},{key:"renderHeader",value:function(){if(this.props.showHeader){var t=this.renderFilter(),n=t;if(this.props.header)n=o.getJSXElement(this.props.header,{filterContainerClassName:"p-tree-filter-container",filterIconClasssName:"p-tree-filter-icon pi pi-search",filterInput:{className:"p-tree-filter p-inputtext p-component",onKeyDown:this.onFilterInputKeyDown,onChange:this.onFilterInputChange},filterElement:t,element:n,props:this.props});return e.createElement("div",{className:"p-tree-header"},n)}return null}},{key:"renderFooter",value:function(){var t=o.getJSXElement(this.props.footer,this.props);return e.createElement("div",{className:"p-tree-footer"},t)}},{key:"render",value:function(){var t=r("p-tree p-component",this.props.className,{"p-tree-selectable":this.props.selectionMode,"p-tree-loading":this.props.loading,"p-disabled":this.props.disabled}),n=this.renderLoader(),o=this.renderModel(),i=this.renderHeader(),s=this.renderFooter();return e.createElement("div",{id:this.props.id,className:t,style:this.props.style},n,i,o,s)}}]),g}();S(j,"defaultProps",{id:null,value:null,disabled:!1,selectionMode:null,selectionKeys:null,onSelectionChange:null,contextMenuSelectionKey:null,onContextMenuSelectionChange:null,expandedKeys:null,style:null,className:null,contentStyle:null,contentClassName:null,metaKeySelection:!0,propagateSelectionUp:!0,propagateSelectionDown:!0,loading:!1,loadingIcon:"pi pi-spinner",dragdropScope:null,header:null,footer:null,showHeader:!0,filter:!1,filterValue:null,filterBy:"label",filterMode:"lenient",filterPlaceholder:null,filterLocale:void 0,nodeTemplate:null,togglerTemplate:null,onSelect:null,onUnselect:null,onExpand:null,onCollapse:null,onToggle:null,onDragDrop:null,onContextMenu:null,onFilterValueChange:null,onNodeClick:null,onNodeDoubleClick:null});export{j as Tree};