import{__spreadArray as e,__assign as o}from"tslib";import{jsxs as n,jsx as i}from"react/jsx-runtime";import{Plus as d,Pencil as t,Trash2 as l}from"lucide-react";import r from"../../styles/ScopeTree.module.css.js";import{TreeNodeHeader as a}from"./TreeNodeHeader.js";import{TreeSectionItem as c}from"./TreeSectionItem.js";import{TreeAddAction as s}from"./TreeAddAction.js";import{dt as p}from"../../store/useLMSConfigStore.js";import{MIDDLE_DRAWER_DT_PATH as u,MIDDLE_DRAWER_CONTEXT_MENU_DT_PATH as h}from"../../constants.js";var m=function(v){var C,f,b,g,S=v.node,y=v.depth,T=void 0===y?0:y,x=v.nodePath,L=void 0===x?[]:x,A=v.expandedNodeIds,N=v.activeSelection,j=v.onToggleExpand,k=v.onSectionSelect,w=v.onNodeOptionsClick,D=v.onAddChild,E=v.onRenameChild,P=v.onDeleteChild,I=v.canDeleteScope,V=v.canEditScope,O=v.canCreateScope,Q=v.searchQuery,R=v.sectionsConfig,Y=void 0===R?[]:R,K=v.nodeTypesConfig,W=void 0===K?[]:K,H=v.forceVisible,M=void 0!==H&&H,q=e(e([],L,!0),[S.id],!1),z=A.has(S.id),B=p("".concat(u,".scope")),F=!!N&&N.nodePath[N.nodePath.length-1]===S.id,G=!!N&&(N.nodePath.includes(S.id)&&!F),J=function(e,o){if(!o)return!0;var n=o.toLowerCase();return!!e.name.toLowerCase().includes(n)||!!e.children&&e.children.some(function(e){return J(e,o)})};if(!M&&!J(S,Q||""))return null;var U=T>=W.length-1?W[W.length-1]:W[T],X=!!(null==U?void 0:U.addChildType),Z=!I||I(S.id),$=!V||V(S.id),_=!O||O(S.id),ee=S.children&&S.children.length>0,oe=!Z||ee,ne=Z?ee?"This scope cannot be deleted because other scopes inherit learnings from it.":void 0:"You do not have permission to delete this scope.",ie=_?void 0:"You do not have permission to add a scope here.",de=!Q||S.name.toLowerCase().includes(Q.toLowerCase());return n("div",o({className:r.nodeWrapper,style:{"--tree-depth":T}},{children:[i(a,{nodeType:S.type,name:S.name,isExpanded:z,isSelected:F,isAncestor:G,childrenCount:null===(C=S.children)||void 0===C?void 0:C.length,onToggleExpand:function(e){e.stopPropagation(),j(S.id)},onClick:function(){k(q,"learnings")},searchQuery:Q,menuOptions:e(e([],X?[{label:U.addChildLabel||"Add Child",icon:d,onClick:function(){return null==D?void 0:D(S.id,U.addChildType,S.name)},disabled:!_,tooltip:ie}]:[],!0),[{label:"".concat(p("".concat(h,".rename"),"Rename")),icon:t,onClick:function(){return null==E?void 0:E(S.id,S.name)},disabled:!$||"station"===(null===(f=null==S?void 0:S.type)||void 0===f?void 0:f.toLocaleLowerCase()),tooltip:$?void 0:"You do not have permission to rename this scope."},{label:"station"===(null===(b=null==S?void 0:S.type)||void 0===b?void 0:b.toLowerCase())?"Delete Station":" ".concat(p("".concat(h,".delete"),"Delete ".concat((null==U?void 0:U.label)||"Node"),{scope:B})),icon:l,onClick:function(){var e;return null==P?void 0:P(S.id,S.name,(null===(e=S.metrics)||void 0===e?void 0:e.learningsCount)||0)},disabled:oe,tooltip:ne,className:"text-red-500 hover:text-red-600 hover:bg-red-50"}],!1)}),z&&n("div",o({className:r.childrenWrapper},{children:[Y.filter(function(e){return!e.isVisible||e.isVisible(S,T)}).map(function(e){var o;return i(c,{icon:e.icon,label:e.label,badgeCount:e.badgeKey?null===(o=S.metrics)||void 0===o?void 0:o[e.badgeKey]:void 0,isActive:F&&(null==N?void 0:N.sectionId)===e.id,onClick:function(){return k(q,e.id)}},"".concat(S.id,"-").concat(e.id))}),null===(g=S.children)||void 0===g?void 0:g.map(function(e){return i(m,{node:e,depth:T+1,nodePath:q,expandedNodeIds:A,activeSelection:N,onToggleExpand:j,onSectionSelect:k,onNodeOptionsClick:w,onAddChild:D,onRenameChild:E,onDeleteChild:P,canDeleteScope:I,canEditScope:V,canCreateScope:O,searchQuery:Q,forceVisible:de,sectionsConfig:Y,nodeTypesConfig:W},e.id)}),X&&i(s,{label:U.addChildLabel||"Add Child",onAdd:function(){return null==D?void 0:D(S.id,U.addChildType,S.name)},disabled:!_,tooltip:ie})]}))]}))};export{m as TreeNode};
//# sourceMappingURL=TreeNode.js.map
