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