"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var files_exports = {};
__export(files_exports, {
  register: () => register
});
module.exports = __toCommonJS(files_exports);
var path = __toESM(require("path"));
var import_ui = require("../ui");
function printTree(nodes, prefix, metadata) {
  for (let i = 0; i < nodes.length; i++) {
    const node = nodes[i];
    const isLast = i === nodes.length - 1;
    const connector = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
    const childPrefix = prefix + (isLast ? "    " : "\u2502   ");
    const meta = metadata && node.type === "file" && node.language ? `  \x1B[90m[${node.language}${node.symbolCount ? ` \xB7 ${node.symbolCount} symbols` : ""}]\x1B[0m` : "";
    console.log(`${prefix}${connector}${node.name}${meta}`);
    if (node.children?.length) printTree(node.children, childPrefix, metadata);
  }
}
function printFlat(nodes, metadata, _prefix = "") {
  for (const node of nodes) {
    if (node.type === "file") {
      const meta = metadata && node.language ? `  \x1B[90m[${node.language}]\x1B[0m` : "";
      console.log(`${node.path}${meta}`);
    }
    if (node.children) printFlat(node.children, metadata);
  }
}
function printGrouped(nodes, metadata) {
  const byLang = /* @__PURE__ */ new Map();
  function collect(ns) {
    for (const n of ns) {
      if (n.type === "file" && n.language) {
        const arr = byLang.get(n.language) ?? [];
        arr.push(n.path);
        byLang.set(n.language, arr);
      }
      if (n.children) collect(n.children);
    }
  }
  collect(nodes);
  for (const [lang, files] of byLang) {
    console.log(`
  ${import_ui.violet}${import_ui.bold}${lang}${import_ui.reset}  ${import_ui.dim}(${files.length})${import_ui.reset}`);
    for (const f of files) console.log(`  ${import_ui.dim}${f}${import_ui.reset}`);
  }
}
function register(program) {
  program.command("files [projectPath]").description("Show project file structure from the index").option("--format <fmt>", "Output format: tree, flat, grouped", "tree").option("--filter <path>", "Filter by directory prefix").option("--pattern <glob>", "Filter by glob pattern").option("--max-depth <n>", "Limit tree depth").option("--no-metadata", "Hide language/symbol counts").option("--json", "Output as JSON").action(async (projectPath, opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(projectPath ?? process.cwd());
    const cg = await KiroGraph.open(target);
    const tree = cg.getFiles({
      filterPath: opts.filter,
      pattern: opts.pattern,
      maxDepth: opts.maxDepth ? parseInt(opts.maxDepth) : void 0
    });
    if (opts.json) {
      console.log(JSON.stringify(tree, null, 2));
      cg.close();
      return;
    }
    if (opts.format === "flat") {
      printFlat(tree, opts.metadata);
    } else if (opts.format === "grouped") {
      printGrouped(tree, opts.metadata);
    } else {
      printTree(tree, "", opts.metadata);
    }
    cg.close();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=files.js.map
