"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 path_exports = {};
__export(path_exports, {
  register: () => register
});
module.exports = __toCommonJS(path_exports);
var path = __toESM(require("path"));
var import_ui = require("../ui");
function register(program) {
  program.command("path <from> <to>").description("Find the shortest path between two symbols in the graph").option("--format <fmt>", "Output format: table | json", "table").action(async (from, to, opts, cmd) => {
    const projectPath = cmd.parent?.args.find((_, i, arr) => arr[i - 1] === "--path");
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(process.cwd());
    const cg = await KiroGraph.open(target);
    const fromResults = cg.searchNodes(from, void 0, 3);
    const toResults = cg.searchNodes(to, void 0, 3);
    if (fromResults.length === 0) {
      console.error(`
  Symbol "${from}" not found in index.
`);
      cg.close();
      return;
    }
    if (toResults.length === 0) {
      console.error(`
  Symbol "${to}" not found in index.
`);
      cg.close();
      return;
    }
    const SYMBOL_KINDS = /* @__PURE__ */ new Set(["function", "method", "class", "interface", "type_alias", "variable", "component", "route", "constant"]);
    const preferSymbol = (results) => results.find((r) => SYMBOL_KINDS.has(r.node.kind)) ?? results[0];
    const fromNode = preferSymbol(fromResults).node;
    const toNode = preferSymbol(toResults).node;
    const pathNodes = await cg.findPath(fromNode.id, toNode.id);
    cg.close();
    if (opts.format === "json") {
      console.log(JSON.stringify(pathNodes, null, 2));
      return;
    }
    console.log();
    console.log(`  ${import_ui.dim}from  ${import_ui.reset}${import_ui.violet}${import_ui.bold}${fromNode.name}${import_ui.reset}  ${import_ui.dim}${fromNode.kind}  ${fromNode.filePath}:${fromNode.startLine}${import_ui.reset}`);
    console.log(`  ${import_ui.dim}to    ${import_ui.reset}${import_ui.violet}${import_ui.bold}${toNode.name}${import_ui.reset}  ${import_ui.dim}${toNode.kind}  ${toNode.filePath}:${toNode.startLine}${import_ui.reset}
`);
    if (pathNodes.length === 0) {
      console.log(`  ${import_ui.dim}No path found.${import_ui.reset}
`);
      return;
    }
    console.log(`  ${import_ui.violet}${import_ui.bold}Path${import_ui.reset}  ${import_ui.dim}${pathNodes.length} hop${pathNodes.length === 1 ? "" : "s"}${import_ui.reset}
`);
    for (let i = 0; i < pathNodes.length; i++) {
      const n = pathNodes[i];
      const connector = i < pathNodes.length - 1 ? `
  ${import_ui.dim}\u2502${import_ui.reset}` : "";
      console.log(`  ${import_ui.dim}${String(i + 1).padStart(2)}.${import_ui.reset} ${import_ui.violet}${import_ui.bold}${n.name}${import_ui.reset}  ${import_ui.dim}${n.kind}${import_ui.reset}`);
      console.log(`      ${import_ui.dim}${n.filePath}:${n.startLine}${import_ui.reset}${connector}`);
    }
    console.log();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=path.js.map
