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