"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var node_tree_traversal_exports = {};
__export(node_tree_traversal_exports, {
  buildNodeTree: () => buildNodeTree
});
module.exports = __toCommonJS(node_tree_traversal_exports);
function buildNodeTree(nodes, depth = 0, parent, refMap = /* @__PURE__ */ new WeakMap()) {
  const tree = [];
  const map = {};
  nodes.forEach((node, index) => {
    const nodeWithMetadata = {
      node,
      index,
      depth,
      parent,
      children: []
    };
    const nodeKey = node.id || `${depth}-${index}`;
    map[nodeKey] = nodeWithMetadata;
    refMap.set(node, nodeWithMetadata);
    if (node.nodes && node.nodes.length > 0) {
      const { tree: childTree, map: childMap } = buildNodeTree(
        node.nodes,
        depth + 1,
        nodeWithMetadata,
        refMap
      );
      nodeWithMetadata.children = childTree;
      Object.assign(map, childMap);
    }
    tree.push(nodeWithMetadata);
  });
  return { tree, map, refMap };
}
//# sourceMappingURL=node-tree-traversal.js.map
