"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 snapshot_exports = {};
__export(snapshot_exports, {
  register: () => register
});
module.exports = __toCommonJS(snapshot_exports);
var path = __toESM(require("path"));
var import_ui = require("../ui");
function register(program) {
  const snapshotCmd = program.command("snapshot").description("Save or list graph snapshots for later diffing");
  snapshotCmd.command("save [label]").description("Save a snapshot of the current graph state").option("--path <p>", "Project root path").action(async (label, opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(opts.path ?? process.cwd());
    const cg = await KiroGraph.open(target);
    const sm = cg.createSnapshotManager();
    const snapshot = sm.save(label);
    cg.close();
    console.log();
    console.log(`  ${import_ui.green}\u2713${import_ui.reset} Snapshot saved: ${import_ui.violet}${import_ui.bold}${snapshot.label}${import_ui.reset}`);
    console.log(`  ${import_ui.dim}${snapshot.nodeCount} symbols, ${snapshot.edgeCount} edges${import_ui.reset}`);
    console.log();
  });
  snapshotCmd.command("list").description("List saved snapshots").option("--path <p>", "Project root path").action(async (opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(opts.path ?? process.cwd());
    const cg = await KiroGraph.open(target);
    const sm = cg.createSnapshotManager();
    const snapshots = sm.list();
    cg.close();
    if (snapshots.length === 0) {
      console.log(`
  ${import_ui.dim}No snapshots yet. Run \`kirograph snapshot save\` first.${import_ui.reset}
`);
      return;
    }
    console.log();
    console.log(`  ${import_ui.violet}${import_ui.bold}Snapshots${import_ui.reset}
`);
    for (const s of snapshots) {
      const date = new Date(s.timestamp).toISOString().slice(0, 19).replace("T", " ");
      console.log(`  ${import_ui.violet}${import_ui.bold}${s.label}${import_ui.reset}  ${import_ui.dim}${date}  ${s.nodeCount} symbols, ${s.edgeCount} edges${import_ui.reset}`);
    }
    console.log();
  });
  snapshotCmd.command("diff [label]").description("Diff current graph vs a saved snapshot (defaults to latest)").option("--path <p>", "Project root path").option("--format <fmt>", "Output format: summary | full | json", "summary").action(async (label, opts) => {
    const KiroGraph = (await Promise.resolve().then(() => require("../../index.js"))).default;
    const target = path.resolve(opts.path ?? process.cwd());
    const cg = await KiroGraph.open(target);
    const sm = cg.createSnapshotManager();
    const snapshot = label ? sm.load(label) : sm.loadLatest();
    if (!snapshot) {
      console.log(`
  ${import_ui.dim}${label ? `Snapshot "${label}" not found.` : "No snapshots found. Run `kirograph snapshot save` first."} ${import_ui.reset}
`);
      cg.close();
      return;
    }
    const diff = sm.diff(snapshot, sm.currentSnapshot());
    cg.close();
    if (opts.format === "json") {
      console.log(JSON.stringify(diff, null, 2));
      return;
    }
    const fromDate = new Date(diff.from.timestamp).toISOString().slice(0, 19).replace("T", " ");
    console.log();
    console.log(`  ${import_ui.violet}${import_ui.bold}Graph Diff${import_ui.reset}  ${import_ui.dim}"${diff.from.label}" (${fromDate}) \u2192 current${import_ui.reset}
`);
    console.log(`  ${import_ui.green}+${import_ui.reset} ${import_ui.bold}${diff.addedNodes.length}${import_ui.reset}${import_ui.dim} symbols added${import_ui.reset}    ${import_ui.dim}-${import_ui.reset} ${import_ui.bold}${diff.removedNodes.length}${import_ui.reset}${import_ui.dim} symbols removed${import_ui.reset}`);
    console.log(`  ${import_ui.green}+${import_ui.reset} ${import_ui.bold}${diff.addedEdges.length}${import_ui.reset}${import_ui.dim} edges added${import_ui.reset}      ${import_ui.dim}-${import_ui.reset} ${import_ui.bold}${diff.removedEdges.length}${import_ui.reset}${import_ui.dim} edges removed${import_ui.reset}`);
    if (opts.format === "full") {
      if (diff.addedNodes.length > 0) {
        console.log(`
  ${import_ui.dim}Added symbols:${import_ui.reset}`);
        for (const n of diff.addedNodes.slice(0, 50)) {
          console.log(`    ${import_ui.green}+${import_ui.reset} ${import_ui.violet}${n.name}${import_ui.reset}  ${import_ui.dim}${n.kind}  ${n.filePath}${import_ui.reset}`);
        }
        if (diff.addedNodes.length > 50) console.log(`    ${import_ui.dim}\u2026and ${diff.addedNodes.length - 50} more${import_ui.reset}`);
      }
      if (diff.removedNodes.length > 0) {
        console.log(`
  ${import_ui.dim}Removed symbols:${import_ui.reset}`);
        for (const n of diff.removedNodes.slice(0, 50)) {
          console.log(`    ${import_ui.dim}- ${n.name}  ${n.kind}  ${n.filePath}${import_ui.reset}`);
        }
        if (diff.removedNodes.length > 50) console.log(`    ${import_ui.dim}\u2026and ${diff.removedNodes.length - 50} more${import_ui.reset}`);
      }
    }
    console.log();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=snapshot.js.map
