"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureGraphCommand = void 0;
const commander_1 = require("commander");
const chalk_1 = __importDefault(require("chalk"));
const FeatureGraphCompiler_1 = require("../services/FeatureGraphCompiler");
exports.FeatureGraphCommand = new commander_1.Command("feature:graph")
    .description("Visualize the feature dependency graph")
    .option("--json", "output as JSON")
    .action(async (options) => {
    const compiler = new FeatureGraphCompiler_1.FeatureGraphCompiler();
    const graph = await compiler.compileFromContext();
    if (options.json) {
        console.log(JSON.stringify({
            nodes: Array.from(graph.nodes.values()).map((n) => ({
                id: n.id,
                name: n.name,
                status: n.status,
                priority: n.priority,
                completeness: n.completeness,
            })),
            edges: graph.edges,
            rootIds: graph.rootIds,
        }, null, 2));
        return;
    }
    console.log(chalk_1.default.bold("\n🔗 Feature Dependency Graph"));
    console.log(chalk_1.default.dim("─".repeat(60)));
    const order = graph.getDependencyOrder();
    for (let i = 0; i < order.length; i++) {
        const node = order[i];
        const prefix = i === order.length - 1 ? "  └─" : "  ├─";
        const statusIcon = node.status === "completed"
            ? chalk_1.default.green("✓")
            : node.status === "in-progress"
                ? chalk_1.default.yellow("●")
                : chalk_1.default.dim("○");
        console.log(`  ${prefix} ${statusIcon} ${chalk_1.default.bold(node.name)}`);
        const deps = graph.edges
            .filter((e) => e.source === node.id && e.type === "depends_on")
            .map((e) => {
            const dep = graph.nodes.get(e.target);
            return dep?.name || e.target;
        });
        if (deps.length > 0) {
            console.log(`  ${" ".repeat(4)} ${chalk_1.default.dim("depends on:")} ${deps.join(", ")}`);
        }
    }
    console.log(chalk_1.default.dim("─".repeat(60)));
    console.log(`  ${order.length} features, ${graph.edges.length} dependencies`);
    console.log();
});
//# sourceMappingURL=feature-graph.js.map