"use strict";const l=require("react/jsx-runtime"),y=require("react"),m=require("../global.module.cjs"),F=require("../tools/icons.cjs"),t=require("../tools/tools.cjs"),I=require("../vendor.cjs"),W=function L(V){const{as:z="div",checkbox:O,checkMode:u,className:D,dropOldClass:M,label:f,level:E,nodeKey:x,onCheck:b,onOptionChange:g,onSelect:K,onToggle:T,option:h,options:v,parentKey:r,style:P,treeMap:s,useCustomSearch:G,variables:q,...H}=V,{checked:J=!1,children:S,disabled:_=!1,expanded:j=!1,highlighted:Q=!1,indeterminate:$,selectable:X=!0}=h,Y=y.useMemo(()=>{const n=t.classx(!M&&"",D),o=t.stylex((d,e)=>({tKey:t.convertBsKeyToVar(e)}),q,P);return{className:n,style:o}},[D,M,P,q]),c=y.useCallback(n=>{var R;const o={...h},d=x===r?{nodeKey:r}:{nodeKey:`${r}-${h.id}`,parentKey:r};let e=v;const w=()=>{e=t.updateTreeNodeUsingMap(e,s,d.nodeKey,i=>(Object.assign(i,o),i))},k=i=>{e=t.updateTreeNodesUsingMap(e,s,i??Array.from(s.keys()),p=>p)},U=()=>{const i=!o.checked,p=a=>(a.checked=i,a),ne=()=>{const a=[d.nodeKey,...t.findTreeNodeParentKeys(d.nodeKey,s),...t.findTreeNodeChildKeys(d.nodeKey,s)];e=t.updateTreeNodesUsingMap(e,s,a,p),t.updateTreeNodeIndeterminateStatus(e),k(a)},N=()=>{const a=[d.nodeKey,...t.findTreeNodeParentKeys(d.nodeKey,s)];e=t.updateTreeNodesUsingMap(e,s,a,p),t.updateTreeNodeIndeterminateStatus(e),k(a)},C=()=>{const a=[d.nodeKey,...t.findTreeNodeChildKeys(d.nodeKey,s)];e=t.updateTreeNodesUsingMap(e,s,a,p),k(a)};switch(u){case"all":case"parentFirst":ne();break;case"child":i?C():N();break;case"childFirst":i?(C(),N()):(N(),C());break;case"parent":i?N():C();break}},B={check:b,select:K,toggle:T};let A=!1;(R=B[n])==null||R.call(B,{metadata:d,option:o,toggleNode:()=>(A=!0,w(),u&&U(),e),treeMap:s}),!A&&typeof g=="function"&&(n==="toggle"?(o.expanded=!o.expanded,w()):n==="check"&&(u?U():(o.checked=!o.checked,t.updateTreeNodeStatus(e,o),k())),g(e))},[u,x,b,g,K,T,h,v,r,s]),Z=y.useCallback(()=>c("toggle"),[c]),ee=y.useCallback(()=>c("select"),[c]),te=y.useCallback(()=>c("check"),[c]);return l.jsxs(z,{...H,...Y,children:[l.jsxs("div",{className:"d-inline-flex align-items-center align-middle gap-2 mb-1",children:[l.jsx("div",{className:t.classxWithOptions(null,m.treeStyles.brlCursorPointer,"user-select-none d-inline-flex"),onClick:Z,children:j?l.jsx(F.BiChevronDown,{}):l.jsx(F.BiChevronRight,{})}),O&&l.jsx("div",{className:"d-inline-block",children:l.jsx("input",{checked:J,className:"form-check-input",disabled:_,onChange:te,ref:n=>{n&&typeof $=="boolean"&&(n.indeterminate=$)},type:"checkbox"})}),l.jsx("div",{className:t.classxWithOptions(null,X?m.treeStyles.brlCursorPointer:m.treeStyles.brlCursorNotAllowed,_&&`${m.treeStyles.brlCursorDefault} opacity-50`,!G&&Q&&"px-1 text-bg-warning rounded"),onClick:ee,children:typeof f=="function"?f({...h}):f})]}),l.jsx(I.AnimatePresence,{children:j&&l.jsx(I.motion.div,{animate:{height:j?"auto":0},className:"overflow-hidden",exit:{height:0},initial:{height:0},transition:{duration:.35},children:S==null?void 0:S.filter(n=>!n.hidden).map(n=>{const o=r?`${r}-${n.id}`:`${n.id}`;return l.jsx(L,{checkbox:O,checkMode:u,className:"ms-3",label:f,level:E+1,nodeKey:o,onCheck:b,onOptionChange:g,onSelect:K,onToggle:T,option:n,options:v,parentKey:x,treeMap:s},n.id)})})})]})};W.displayName="BRL.TreeNode";exports.TreeNode=W;
//# sourceMappingURL=tree-node.cjs.map
