import{ao as i,aQ as k,aJ as m,T as A,at as E,v as q}from"./app-k0jcl5PQ.js";import{A as S}from"./BDviDDog.chunk.js";import{C as L}from"./sncKO62z.chunk.js";import{T as $}from"./CXQbE3g_.chunk.js";const D="_tree_u0qyb_1",w="_text_u0qyb_1",H="_chevron_u0qyb_4",P="_disabled_u0qyb_163",R="_root_u0qyb_166",O="_selected_u0qyb_172",F="_actions_u0qyb_175",B="_node_u0qyb_185",J="_noActions_u0qyb_188",l={tree:D,text:w,chevron:H,disabled:P,root:R,selected:O,actions:F,node:B,noActions:J};function M(e){var s;function t(){let a=`${l.text} clamp-4`;return e.className&&(a+=` ${e.className}`),a}if(e.isDisabled){const a=typeof e.disabledTooltip=="string"?e.disabledTooltip:(s=e.disabledTooltip)==null?void 0:s.call(e,e.tree);return i.jsx(k,{title:a,spanHack:!0,spanHackClassName:"d-inline-block flex-grow-1",children:i.jsx("span",{className:`${t()} text-secondary ${l.disabled}`,children:e.text})})}return i.jsx("div",{className:t(),children:e.text})}const Q="tree-actions";b.defaultProps={selectedLinkClassName:l.selected};function b(e){const{tree:t,selectedIds:s,getAppLink:a,onSelect:c,isDisabled:r,isClickDisabled:o,actions:d,isDropdown:y}=e,u=m.useRef(null),x=m.useMemo(()=>s==null?void 0:s.some(n=>$.find(t,n)),[t,s]),T=e.openDepth&&e.depth<e.openDepth,[f,h]=m.useState(x||T),g=s==null?void 0:s.some(n=>A.isEqual(t.id,n));let _=!!t.children&&!!t.children.length;e.maxDisplayDepth&&_&&(_=e.depth<e.maxDisplayDepth),m.useEffect(()=>{if(!u.current||!y)return;const n=v=>{v.stopPropagation(),N()};return u.current.addEventListener("click",n),()=>{u.current&&u.current.removeEventListener("click",n)}},[u.current,c]),m.useEffect(()=>{var n;e.multiSelect||f&&(x||g||!((n=e.selectedIds)!=null&&n.length)&&(r!=null&&r(e.tree))||T||h(!1))},[s]);function N(){if(!(o!=null&&o(t))){if(e.multiSelect||h(!f),a){q.trigger(a(t));return}if(r!=null&&r(t)){c(null);return}c==null||c(t)}}function j(n){if(n.stopPropagation(),e.multiSelect){h(!f);return}N()}function C(){let n=`py-1 d-flex align-items-center w-100 position-relative ${l.node}`;return g&&(n+=" "+e.selectedLinkClassName),d!=null&&d.length||(n+=" "+l.noActions),x&&e.multiSelect&&(n+=" text-underline fst-italic"),n}return e.maxDisplayDepth&&e.depth>e.maxDisplayDepth?i.jsx(i.Fragment,{}):i.jsx("li",{className:`position-relative ${f?"":l.collapsed} ${e.isRoot?l.root:""}`,children:i.jsxs("div",{className:"position-relative",children:[i.jsxs(E,{className:C(),onClick:y?null:N,ref:u,children:[_&&i.jsx("div",{className:l.chevron,onClick:j,children:i.jsx(L,{direction:f?"down":"right"})}),i.jsx(M,{tree:t,text:t.name||t.description,isDisabled:(r==null?void 0:r(t))||(o==null?void 0:o(t)),disabledTooltip:e.disabledTooltip})]}),!!e.actions&&i.jsx(S,{className:l.actions,actions:d==null?void 0:d.map(n=>({...n,appLink:n.getAppLink(t)})),actionsDropdownClassName:`btn btn-light ${Q} py-0`}),f&&i.jsx(p,{...e,isChild:!0,depth:e.depth+1},t.id)]})})}function p(e){const{tree:t,...s}=e;return!t||!t.children?i.jsx(i.Fragment,{}):i.jsx("ul",{className:`m-0 p-0 list-unstyled ${l.tree}`,children:t.children.map((a,c)=>i.jsx(b,{tree:a,...s,isRoot:!e.isChild,depth:e.depth||0},c))})}export{p as T};
//# sourceMappingURL=CxXrZYi8.chunk.js.map
