import { jsx as S } from "react/jsx-runtime";
import { useMemo as m } from "react";
import { c as $, s as V, C as w, a as F } from "../tools/tools.js";
import { T as v } from "./tree-node.js";
const D = (y = [], r) => y.map((n, o) => {
  const l = n.id !== void 0 ? n.id : r !== void 0 ? `${r}${o}` : `${o}`;
  return {
    ...n,
    children: n.children ? D(n.children, l) : void 0,
    id: l
  };
}), L = (y, r) => {
  const n = r.toLowerCase(), o = (l) => {
    var h;
    const d = [];
    for (const t of l) {
      const p = (h = t.label) == null ? void 0 : h.toLowerCase(), u = (p == null ? void 0 : p.includes(n)) || !1;
      let a = !u;
      const g = u;
      let c;
      if (t.children && t.children.length > 0) {
        c = o(t.children);
        const f = c.some((i) => !i.hidden);
        a = !u && !f;
      }
      (!a || c) && d.push({
        ...t,
        children: c,
        hidden: a,
        highlighted: g
      });
    }
    return d;
  };
  return o(y);
}, O = function(r) {
  const {
    as: n = "div",
    checkbox: o,
    checkMode: l,
    className: d,
    dropOldClass: h,
    label: t,
    onCheck: p,
    onOptionChange: u,
    onSearch: a,
    onSelect: g,
    onToggle: c,
    options: f,
    searchTerm: i,
    style: T,
    useCustomSearch: b,
    variables: B,
    ...N
  } = r, k = m(() => {
    const e = $(!h && "", d), s = V((K, M) => ({ tKey: F(M) }), B, T);
    return {
      className: e,
      style: s
    };
  }, [d, h, T, B]), C = m(() => {
    let e;
    const s = i == null ? void 0 : i.trim();
    return s ? e = (a || L)(f, s) : e = f, D(e);
  }, [a, f, i]), x = m(() => w(C), [C]);
  return /* @__PURE__ */ S(n, { ...N, ...k, children: C.filter((e) => !e.hidden).map((e) => {
    const s = `${e.id}`;
    return /* @__PURE__ */ S(
      v,
      {
        checkbox: o,
        checkMode: l,
        label: t,
        level: 0,
        nodeKey: s,
        onCheck: p,
        onOptionChange: u,
        onSelect: g,
        onToggle: c,
        option: e,
        options: C,
        parentKey: s,
        treeMap: x,
        useCustomSearch: b
      },
      e.id
    );
  }) });
};
O.Node = v;
O.displayName = "BRL.Tree";
export {
  O as T
};
//# sourceMappingURL=tree.js.map
