"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 file_tree_exports = {};
__export(file_tree_exports, {
  buildFileTree: () => buildFileTree
});
module.exports = __toCommonJS(file_tree_exports);
function buildFileTree(files, maxDepth) {
  const rootMap = /* @__PURE__ */ new Map();
  for (const file of files) {
    const parts = file.path.split("/");
    let currentMap = rootMap;
    for (let i = 0; i < parts.length; i++) {
      if (maxDepth !== void 0 && i >= maxDepth) break;
      const part = parts[i];
      const currentPath = parts.slice(0, i + 1).join("/");
      const isLast = i === parts.length - 1;
      if (!currentMap.has(part)) {
        if (isLast) {
          currentMap.set(part, {
            name: part,
            path: currentPath,
            type: "file",
            language: file.language,
            symbolCount: file.symbolCount
          });
        } else {
          const dir = { name: part, path: currentPath, type: "dir", children: [], _childMap: /* @__PURE__ */ new Map() };
          currentMap.set(part, dir);
        }
      }
      if (!isLast) {
        const dir = currentMap.get(part);
        currentMap = dir._childMap;
      }
    }
  }
  function toTree(map) {
    return [...map.values()].map((n) => {
      if (n.type === "dir") {
        const dir = n;
        return { name: dir.name, path: dir.path, type: "dir", children: toTree(dir._childMap) };
      }
      return n;
    });
  }
  return toTree(rootMap);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildFileTree
});
//# sourceMappingURL=file-tree.js.map
