const s = (n, t = "children") => {
  let r = [];
  for (let e = 0; e < n.length; e++)
    n[e][t] && n[e][t].length > 0 && (r.push(n[e]), r = r.concat(s(n[e][t])));
  return r;
}, l = (n, t = "children", r = !0) => Array.isArray(n) && n.length ? n.reduce((e, u) => {
  let f = u[t], o = { ...u };
  return r && delete o[t], f && f.length ? e.concat(o, l(f, t, r)) : e.concat(o);
}, []) : [], c = (n, t, r = "children") => n.filter((e) => t(e)).map((e) => (e = Object.assign({}, e), e[r] && (e[r] = c(e[r], t)), e)), g = (n, t, r = "children") => {
  for (const e of n) {
    if (t(e)) return e;
    if (e != null && e[r] && e[r].length) {
      const u = g(e[r], t, r = "children");
      if (u) return u;
    }
  }
  return null;
};
export {
  c as filterTreeArray,
  s as findNonEmptyChildrenItems,
  l as flatTree,
  g as treeFind
};
