"use strict";
/**
 * 🏎️ faf show - Championship Score Card Display
 * Shows FAF project score card with clean markdown output
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.showFafScoreCard = showFafScoreCard;
const colors_1 = require("../fix-once/colors");
const fs_1 = require("fs");
const yaml_1 = require("../fix-once/yaml");
const faf_compiler_1 = require("../compiler/faf-compiler");
const file_utils_1 = require("../utils/file-utils");
const color_utils_1 = require("../utils/color-utils");
async function showFafScoreCard(directory, options = {}) {
    try {
        const targetDir = directory || process.cwd();
        // Find .faf file in directory
        const fafPath = await (0, file_utils_1.findFafFile)(targetDir);
        if (!fafPath) {
            console.log(colors_1.chalk.red("❌ No .faf file found"));
            console.log(colors_1.chalk.yellow('💡 Run "faf init" to create one'));
            process.exit(1);
        }
        // Read and parse .faf file
        const content = await fs_1.promises.readFile(fafPath, "utf-8");
        const fafData = (0, yaml_1.parse)(content);
        // Calculate score
        const compiler = new faf_compiler_1.FafCompiler();
        const scoreResult = await compiler.compile(fafPath);
        const percentage = Math.round(scoreResult.score || 0);
        // 🍫🍊 CHOCOLATE ORANGE - NO WRAPPERS!
        // Clean markdown output for direct display
        if (options.raw) {
            // Raw markdown output (for piping, etc.)
            const output = `# 🏎️  FAF Stats

## **Project Score: ${percentage}/100**

${percentage >= 99 ? '🏁 **CHAMPIONSHIP STATUS ACHIEVED!**' :
                percentage >= 80 ? '✨ **Excellent AI Context!**' :
                    percentage >= 60 ? '👍 **Good Foundation**' :
                        '⚠️  **Needs Enhancement**'}

### Project Details
- **Name**: ${typeof fafData.project === 'object' && fafData.project?.name
                ? fafData.project.name
                : (typeof fafData.project === 'string' ? fafData.project : 'Unknown')}
- **Version**: ${fafData.version || '1.0.0'}
- **Stack**: ${typeof fafData.stack === 'object' && fafData.stack?.name
                ? fafData.stack.name
                : (typeof fafData.stack === 'string' ? fafData.stack :
                    (fafData.instant_context?.tech_stack || 'Not specified'))}
${fafData.ai_models ? `- **AI Models**: ${fafData.ai_models.join(', ')}` : ''}

### Score Breakdown
Use \`faf score --details\` for complete breakdown

---
*🏎️ FAF Engine | Championship Grade Context*`;
            console.log(output);
        }
        else {
            // Formatted console output
            const scoreColor = (0, color_utils_1.getScoreColor)(percentage);
            const scoreEmoji = (0, color_utils_1.getScoreEmoji)(percentage);
            console.log(colors_1.chalk.bold.blue("\n🏎️  FAF Stats"));
            console.log(colors_1.chalk.bold.blue("=============\n"));
            // Score display
            console.log(scoreColor(colors_1.chalk.bold(`${scoreEmoji} Project Score: ${percentage}/100`)));
            // Status message
            if (percentage >= 99) {
                console.log(colors_1.chalk.green.bold("🏁 CHAMPIONSHIP STATUS ACHIEVED!"));
            }
            else if (percentage >= 80) {
                console.log(colors_1.chalk.green("✨ Excellent AI Context!"));
            }
            else if (percentage >= 60) {
                console.log(colors_1.chalk.yellow("👍 Good Foundation"));
            }
            else {
                console.log(colors_1.chalk.red("⚠️  Needs Enhancement"));
            }
            // Project details
            console.log(colors_1.chalk.blue("\n📋 Project Details:"));
            // Handle both string and object formats for project name
            const projectName = typeof fafData.project === 'object' && fafData.project?.name
                ? fafData.project.name
                : (typeof fafData.project === 'string' ? fafData.project : 'Unknown');
            console.log(`   Name: ${colors_1.chalk.white(projectName)}`);
            console.log(`   Version: ${colors_1.chalk.white(fafData.version || '1.0.0')}`);
            // Handle both string and object formats for stack
            const stackName = typeof fafData.stack === 'object' && fafData.stack?.name
                ? fafData.stack.name
                : (typeof fafData.stack === 'string' ? fafData.stack :
                    (fafData.instant_context?.tech_stack || 'Not specified'));
            console.log(`   Stack: ${colors_1.chalk.white(stackName)}`);
            if (fafData.ai_models) {
                console.log(`   AI Models: ${colors_1.chalk.white(fafData.ai_models.join(', '))}`);
            }
            // TODO: Add score breakdown back when compiler supports sectionScores
            // console.log(chalk.blue("\n📊 Score Breakdown:"));
            // Object.entries(scoreResult.sectionScores).forEach(([section, score]) => {
            //   const sectionPercentage = Math.round(score.percentage);
            //   const sectionColor = sectionPercentage >= 70 ? chalk.green :
            //                      sectionPercentage >= 40 ? chalk.yellow :
            //                      chalk.red;
            //   console.log(`   ${sectionColor(section)}: ${sectionPercentage}% (${score.filled}/${score.total})`);
            // });
            // Next steps if not perfect
            // TODO: Add suggestions back when compiler supports them
            // if (percentage < 100) {
            //   console.log(chalk.blue("\n💡 Next Steps:"));
            //   scoreResult.suggestions.slice(0, 3).forEach((suggestion: string, index: number) => {
            //     console.log(chalk.yellow(`   ${index + 1}. ${suggestion}`));
            //   });
            // }
            console.log(colors_1.chalk.gray("\n---"));
            console.log(colors_1.chalk.gray("🏎️ FAF Engine | Championship Grade Context"));
        }
    }
    catch (error) {
        console.log(colors_1.chalk.red("💥 Show command failed:"));
        console.log(colors_1.chalk.red(error instanceof Error ? error.message : String(error)));
        process.exit(1);
    }
}
//# sourceMappingURL=show.js.map