"use strict";
/**
 * 🚀 Status Command - The Git Status Equivalent
 * Quick context health check that developers use 20x/day
 *
 * Performance Target: <200ms consistently
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.statusCommand = statusCommand;
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const colors_1 = require("../fix-once/colors");
const file_utils_1 = require("../utils/file-utils");
const championship_style_1 = require("../utils/championship-style");
const color_utils_1 = require("../utils/color-utils");
const championship_core_1 = require("../utils/championship-core");
const faf_compiler_1 = require("../compiler/faf-compiler");
/**
 * Get quick status overview for .faf file
 * NOW USING FAB-FORMATS COMPILER - Championship scoring! 🏆
 */
async function getQuickStatus(fafPath) {
    try {
        const stats = await fs_1.promises.stat(fafPath);
        const fafContent = await fs_1.promises.readFile(fafPath, 'utf-8');
        // Quick health indicators
        const hasBasicStructure = fafContent.includes('project:') && fafContent.includes('metadata:');
        const lines = fafContent.split('\n').length;
        const size = stats.size;
        const lastModified = stats.mtime;
        // USE COMPILER SCORE (not trust score!) - Championship engine 🏎️
        const compiler = new faf_compiler_1.FafCompiler();
        const compilerResult = await compiler.compile(fafPath);
        const score = compilerResult.score || 0;
        // Calculate time since last modification
        const now = new Date();
        const timeDiff = now.getTime() - lastModified.getTime();
        const minutesAgo = Math.floor(timeDiff / (1000 * 60));
        const hoursAgo = Math.floor(minutesAgo / 60);
        const daysAgo = Math.floor(hoursAgo / 24);
        let lastSyncText = '';
        if (daysAgo > 0) {
            lastSyncText = `${daysAgo} day${daysAgo > 1 ? 's' : ''} ago`;
        }
        else if (hoursAgo > 0) {
            lastSyncText = `${hoursAgo} hour${hoursAgo > 1 ? 's' : ''} ago`;
        }
        else if (minutesAgo > 0) {
            lastSyncText = `${minutesAgo} minute${minutesAgo > 1 ? 's' : ''} ago`;
        }
        else {
            lastSyncText = 'just now';
        }
        return {
            trustScore: score, // Actually compiler score now!
            hasBasicStructure,
            lines,
            size,
            lastSyncText,
            isHealthy: hasBasicStructure && score > 70
        };
    }
    catch {
        return {
            trustScore: 0,
            hasBasicStructure: false,
            lines: 0,
            size: 0,
            lastSyncText: 'unknown',
            isHealthy: false
        };
    }
}
/**
 * Check for claude.md file presence (Bi-sync status)
 */
async function checkClaudeMd(projectDir) {
    try {
        const claudeMdPath = path_1.default.join(projectDir, 'claude.md');
        await fs_1.promises.access(claudeMdPath);
        return true;
    }
    catch {
        return false;
    }
}
/**
 * Get tier information for current score and next target
 * NOW USING CHAMPIONSHIP CORE - The DNA both brothers share! 🏆
 */
const getTierInfo = championship_core_1.getTierInfo;
/**
 * 🏁 Championship Status Dashboard - <38ms Performance Target
 */
function displayStatus(fafPath, status, hasClaudeMd, duration) {
    const { trustScore, lines, lastSyncText } = status;
    // Championship performance check
    const performanceGrade = duration <= championship_style_1.PERFORMANCE_STANDARDS.status_command ? 'CHAMPION' : 'GOOD';
    const speedEmoji = duration <= championship_style_1.PERFORMANCE_STANDARDS.status_command ? championship_style_1.FAF_ICONS.trophy : championship_style_1.FAF_ICONS.lightning;
    // Calculate Technical Credit (mock for now)
    const technicalCredit = Math.floor((trustScore - 50) / 10) * 5;
    // Get medal emoji and tier info
    const medal = (0, color_utils_1.getScoreEmoji)(trustScore);
    const tierInfo = getTierInfo(trustScore);
    console.log();
    console.log(championship_style_1.FAF_COLORS.fafCyan('🏎️  FAF Status'));
    console.log(championship_style_1.FAF_COLORS.fafCyan('━━━━━━━━━━━━'));
    console.log(`Score: ${trustScore}% ${medal} ${tierInfo.current}`);
    if (tierInfo.next && tierInfo.nextTarget) {
        console.log(`Next: ${tierInfo.nextTarget}% ${tierInfo.nextMedal} ${tierInfo.next} (${tierInfo.nextTarget - trustScore}% to go!)`);
    }
    console.log();
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('├─ ')}${championship_style_1.FAF_ICONS.robot} AI Readiness: ${trustScore >= 80 ? '☑️ Optimized' : '🟡 Improving'}`);
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('├─ ')}${championship_style_1.FAF_ICONS.file} Files Tracked: ${lines} lines`);
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('├─ ')}${championship_style_1.FAF_ICONS.zap} Performance: ${(0, championship_style_1.formatPerformance)(duration)}`);
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('├─ ')}${championship_style_1.FAF_ICONS.heart_orange} Last Sync: ${lastSyncText}`);
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('└─ ')}${championship_style_1.FAF_ICONS.chart_up} Technical Credit: ${(0, championship_style_1.formatTechnicalCredit)(technicalCredit)}`);
    console.log();
    // AI Happiness Status
    console.log(championship_style_1.FAF_COLORS.fafGreen(`${championship_style_1.FAF_ICONS.brain} AI Compatibility:`));
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('   ├─ ')}${championship_style_1.FAF_ICONS.blue_heart} Claude: ${trustScore >= 85 ? '92% 🩵' : trustScore >= 70 ? '78% 🟡' : '54% 🟠'}`);
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('   ├─ ')}${championship_style_1.FAF_ICONS.green_heart} ChatGPT: ${trustScore >= 80 ? '89% 💚' : trustScore >= 65 ? '71% 🟡' : '49% 🟠'}`);
    console.log(`${championship_style_1.FAF_COLORS.fafCyan('   └─ ')}${championship_style_1.FAF_ICONS.heart_orange} Gemini: ${trustScore >= 75 ? '84% 🧡' : trustScore >= 60 ? '68% 🟡' : '43% 🟠'}`);
    console.log();
    // Bi-sync status with Championship styling
    if (hasClaudeMd) {
        console.log(championship_style_1.FAF_COLORS.fafGreen(`☑️ claude.md found - ${championship_style_1.FAF_ICONS.link} Bi-sync active`));
    }
    else {
        console.log(championship_style_1.FAF_COLORS.fafOrange(`⚠️  claude.md not found - run `) + championship_style_1.FAF_COLORS.fafCyan('faf bi-sync') + championship_style_1.FAF_COLORS.fafOrange(' to create'));
    }
    console.log();
    // Championship Call to Action
    if (duration <= championship_style_1.PERFORMANCE_STANDARDS.status_command && trustScore >= 85) {
        console.log(championship_style_1.FAF_COLORS.fafGreen(`${championship_style_1.FAF_ICONS.party} Championship performance! ${championship_style_1.FAF_ICONS.trophy}`));
        console.log(`${championship_style_1.FAF_COLORS.fafCyan(`${championship_style_1.FAF_ICONS.rocket} Try: `)}faf share${championship_style_1.FAF_COLORS.fafCyan(' - Share this excellence!')}`);
    }
    else {
        console.log(`${championship_style_1.FAF_COLORS.fafCyan(`${championship_style_1.FAF_ICONS.magic_wand} Try: `)}faf trust --detailed${championship_style_1.FAF_COLORS.fafCyan(' - Improve your context')}`);
    }
    console.log();
}
/**
 * Main status command handler
 */
async function statusCommand() {
    const startTime = Date.now();
    try {
        const fafPath = await (0, file_utils_1.findFafFile)();
        if (!fafPath) {
            console.log(colors_1.chalk.red('❌ No .faf file found'));
            console.log(colors_1.chalk.dim('💡 Run `faf init` to get started'));
            process.exit(1);
        }
        const projectDir = path_1.default.dirname(fafPath);
        const [status, hasClaudeMd] = await Promise.all([
            getQuickStatus(fafPath),
            checkClaudeMd(projectDir)
        ]);
        const duration = Date.now() - startTime;
        displayStatus(fafPath, status, hasClaudeMd, duration);
        // Return instead of exit so footer can show
        if (!status.isHealthy) {
            // Let analytics wrapper handle footer display
            return;
        }
    }
    catch (error) {
        console.error(colors_1.chalk.red('❌ Error checking status:'), error);
        process.exit(1);
    }
}
//# sourceMappingURL=status.js.map