"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusCommand = void 0;
const chalk_1 = __importDefault(require("chalk"));
const fileSystem_1 = require("../utils/fileSystem");
class StatusCommand {
    constructor() {
        this.fs = new fileSystem_1.FileSystemManager();
    }
    async execute(target, options) {
        try {
            console.log(chalk_1.default.blue.bold("📊 MyContext Project Status\n"));
            // Check if we're in a MyContext project
            const isProject = await this.fs.isMyContextProject(".");
            if (!isProject) {
                console.log(chalk_1.default.yellow("❌ Not a MyContext project"));
                console.log(chalk_1.default.gray('Run "mycontext init <project-name>" to create a new project.\n'));
                return;
            }
            // Get project configuration
            const config = await this.fs.getProjectConfig(".");
            if (!config) {
                console.log(chalk_1.default.red("❌ Project configuration not found"));
                return;
            }
            // Display project status
            await this.displayProjectStatus(config, options);
            // Check health if requested
            if (options.checkHealth) {
                await this.checkProjectHealth(config);
            }
        }
        catch (error) {
            console.error(chalk_1.default.red("❌ Status check failed:"), error);
            throw error;
        }
    }
    async displayProjectStatus(config, options) {
        // Project overview
        console.log(chalk_1.default.cyan("📁 Project Overview:"));
        console.log(`  Name: ${chalk_1.default.bold(config.name)}`);
        console.log(`  Description: ${chalk_1.default.gray(config.description)}`);
        console.log(`  Version: ${config.version}`);
        console.log(`  Status: ${this.getStatusBadge(config.status)}`);
        console.log(`  Created: ${new Date(config.createdAt).toLocaleDateString()}`);
        console.log(`  Updated: ${new Date(config.updatedAt).toLocaleDateString()}\n`);
        // Progress tracking
        await this.displayProgress(config);
        // File status
        await this.displayFileStatus();
        // Next steps
        this.displayNextSteps(config.status);
    }
    async displayProgress(config) {
        console.log(chalk_1.default.cyan("🎯 Progress:"));
        const progressSteps = [
            { key: "initialized", label: "Project Initialized", icon: "✅" },
            {
                key: "context-generated",
                label: "Context Files Generated",
                icon: "📝",
            },
            { key: "branded", label: "Branding Guidelines", icon: "🎨" },
            { key: "components-planned", label: "Components Planned", icon: "🧩" },
            { key: "generating", label: "Components Generating", icon: "⚡" },
            { key: "completed", label: "Project Complete", icon: "🎉" },
        ];
        const currentIndex = progressSteps.findIndex((step) => step.key === config.status);
        progressSteps.forEach((step, index) => {
            const isCompleted = index <= currentIndex;
            const isCurrent = index === currentIndex;
            let icon = step.icon;
            let color = chalk_1.default.gray;
            if (isCompleted) {
                icon = "✅";
                color = chalk_1.default.green;
            }
            else if (isCurrent) {
                icon = "🔄";
                color = chalk_1.default.yellow;
            }
            console.log(`  ${icon} ${color(step.label)}`);
        });
        console.log("");
    }
    async displayFileStatus() {
        console.log(chalk_1.default.cyan("📄 Files Status:"));
        const expectedFiles = [
            { path: ".mycontext/01-prd.md", name: "PRD", required: true },
            {
                path: ".mycontext/02-types.ts",
                name: "TypeScript Types",
                required: false,
            },
            {
                path: ".mycontext/03-branding.md",
                name: "Branding Guidelines",
                required: false,
            },
            {
                path: ".mycontext/04-component-list.json",
                name: "Component List",
                required: false,
            },
        ];
        for (const file of expectedFiles) {
            try {
                await this.fs.readFile(file.path);
                console.log(`  ✅ ${chalk_1.default.green(file.name)}`);
            }
            catch {
                if (file.required) {
                    console.log(`  ❌ ${chalk_1.default.red(file.name)} (Missing)`);
                }
                else {
                    console.log(`  ⚪ ${chalk_1.default.gray(file.name)} (Not generated)`);
                }
            }
        }
        console.log("");
    }
    displayNextSteps(currentStatus) {
        console.log(chalk_1.default.cyan("🎯 Next Steps:"));
        const nextSteps = this.getNextSteps(currentStatus);
        nextSteps.forEach((step, index) => {
            console.log(`  ${index + 1}. ${step}`);
        });
        console.log("");
    }
    getNextSteps(status) {
        switch (status) {
            case "initialized":
                return [
                    'Run "mycontext generate context" to create PRD and user stories',
                    "Edit the generated PRD to match your requirements",
                    'Run "mycontext validate prd" to check quality',
                ];
            case "context-generated":
                return [
                    'Run "mycontext generate types" to create TypeScript definitions',
                    'Run "mycontext generate brand" to create branding guidelines',
                    "Review and refine your context files",
                ];
            case "branded":
                return [
                    'Run "mycontext generate components" to plan your component library',
                    "Review the component list and adjust priorities",
                    'Run "mycontext generate app-structure" to plan your app architecture',
                ];
            case "components-planned":
                return [
                    "Start implementing components based on the generated list",
                    "Use the context files with your AI development tools",
                    'Run "mycontext status" to track progress',
                ];
            case "generating":
                return [
                    "Wait for component generation to complete",
                    "Review generated components",
                    "Start development with the generated context",
                ];
            case "completed":
                return [
                    "Start development with your generated context",
                    "Use the context files with local AI models or other development tools",
                    "Update context files as requirements evolve",
                ];
            default:
                return [
                    'Run "mycontext init <project-name>" to start a new project',
                    "Check the documentation at https://mycontext.fbien.com/docs",
                ];
        }
    }
    async checkProjectHealth(config) {
        console.log(chalk_1.default.cyan("🏥 Health Check:"));
        const healthChecks = [
            {
                name: "Project Configuration",
                check: () => this.checkConfigHealth(config),
            },
            { name: "Context Files", check: () => this.checkContextHealth() },
            { name: "File Permissions", check: () => this.checkPermissions() },
        ];
        let allHealthy = true;
        for (const healthCheck of healthChecks) {
            try {
                const isHealthy = await healthCheck.check();
                const icon = isHealthy ? "✅" : "❌";
                const color = isHealthy ? chalk_1.default.green : chalk_1.default.red;
                console.log(`  ${icon} ${color(healthCheck.name)}`);
                if (!isHealthy) {
                    allHealthy = false;
                }
            }
            catch (error) {
                console.log(`  ❌ ${chalk_1.default.red(healthCheck.name)} (Error)`);
                allHealthy = false;
            }
        }
        console.log("");
        if (allHealthy) {
            console.log(chalk_1.default.green("🎉 Project is healthy!"));
        }
        else {
            console.log(chalk_1.default.yellow("⚠️ Some issues found. Check the details above."));
        }
        console.log("");
    }
    async checkConfigHealth(config) {
        return !!(config.name && config.description && config.id);
    }
    async checkContextHealth() {
        try {
            const files = await this.fs.listContextFiles(".");
            return files.length > 0;
        }
        catch {
            return false;
        }
    }
    async checkPermissions() {
        try {
            // Try to write a test file
            const testPath = ".mycontext/test-permissions.tmp";
            await this.fs.writeFile(testPath, "test");
            await this.fs.readFile(testPath);
            // Clean up
            await Promise.resolve().then(() => __importStar(require("fs-extra"))).then((fs) => fs.remove(testPath));
            return true;
        }
        catch {
            return false;
        }
    }
    getStatusBadge(status) {
        const badges = {
            initialized: chalk_1.default.blue("● Initialized"),
            "context-generated": chalk_1.default.green("● Context Generated"),
            branded: chalk_1.default.cyan("● Branded"),
            "components-planned": chalk_1.default.yellow("● Components Planned"),
            generating: chalk_1.default.magenta("● Generating"),
            completed: chalk_1.default.green("● Completed"),
        };
        return badges[status] || chalk_1.default.gray("● Unknown");
    }
}
exports.StatusCommand = StatusCommand;
//# sourceMappingURL=status.js.map