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