"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("tslib"),n=require("react/jsx-runtime"),t=require("react"),o=require("../../styles/ScopeTree.module.css.js"),i=require("../../utils/treeUtils.js"),r=require("./TreeNode.js");exports.TreeSidebar=function(c){var d=c.data,a=c.defaultExpandedIds,u=void 0===a?[]:a,s=c.onSectionSelect,l=c.onNodeOptionsClick,f=c.onAddChild,h=c.onRenameChild,S=c.onDeleteChild,C=c.canDeleteScope,p=c.canEditScope,v=c.canCreateScope,E=c.searchQuery,g=void 0===E?"":E,w=c.onSearchCountChange,x=c.sectionsConfig,y=c.nodeTypesConfig,j=c.selectedRuleSetId,m=c.activeSectionId,I=t.useState(new Set(d?e.__spreadArray([d.id],u,!0):u)),N=I[0],T=I[1],q=t.useState(null),_=q[0],D=q[1];t.useEffect(function(){d&&T(function(e){if(!e.has(d.id)){var n=new Set(e);return n.add(d.id),n}return e})},[null==d?void 0:d.id]),t.useEffect(function(){if(d&&j&&m){var e=i.findNodePathById(d,j);e&&(D({nodePath:e,sectionId:m}),T(function(n){var t=new Set(n);return e.forEach(function(e){return t.add(e)}),t}))}},[d,j,m]),t.useEffect(function(){if(g&&d){var e=new Set,n=function(t){var o=g.toLowerCase(),i=t.name.toLowerCase().includes(o),r=!1;t.children&&t.children.forEach(function(e){n(e)&&(r=!0)});var c=i||r;return c&&r&&e.add(t.id),c};n(d),T(e)}},[g,d]);var L=function(e,n){if(!n)return 0;var t=0,o=n.toLowerCase();return e.name.toLowerCase().includes(o)&&t++,e.children&&e.children.forEach(function(e){t+=L(e,n)}),t};t.useEffect(function(){w&&d&&w(L(d,g))},[g,d,w]);return d?n.jsx("div",e.__assign({className:o.default.treeContainer},{children:n.jsx(r.TreeNode,{node:d,expandedNodeIds:N,activeSelection:_,onToggleExpand:function(e){T(function(n){var t=new Set(n);return t.has(e)?t.delete(e):t.add(e),t})},onSectionSelect:function(e,n){console.log("handleSectionSelect",e,n),D({nodePath:e,sectionId:n}),s&&s(e[e.length-1],n)},onNodeOptionsClick:function(e){l&&l(e)},onAddChild:function(e,n,t){f&&f(e,n,t)},onRenameChild:function(e,n){h&&h(e,n)},onDeleteChild:function(e,n,t){S&&S(e,n,t)},canDeleteScope:C,canEditScope:p,searchQuery:g,sectionsConfig:x,nodeTypesConfig:y,canCreateScope:v})})):null};
//# sourceMappingURL=TreeSidebar.js.map
