"use strict";
/**
 * 🩵 faf faq - FAQ Command
 * Display FAQ and search functionality
 */
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.faqCommand = faqCommand;
const colors_1 = require("../fix-once/colors");
const fs_1 = require("fs");
const path_1 = __importDefault(require("path"));
const championship_style_1 = require("../utils/championship-style");
/**
 * Display FAQ content
 */
async function faqCommand(options = {}) {
    try {
        const faqPath = path_1.default.join(__dirname, '../../FAQ.md');
        // Check if FAQ file exists
        let faqContent;
        try {
            faqContent = await fs_1.promises.readFile(faqPath, 'utf-8');
        }
        catch {
            // Fallback if FAQ.md not found in expected location
            console.log(championship_style_1.FAF_COLORS.fafOrange('📄 FAQ file not found at expected location.'));
            console.log(colors_1.chalk.dim('💡 FAQ content is available in the repository at FAQ.md'));
            return;
        }
        console.log();
        if (options.search) {
            // Search functionality
            const searchTerm = options.search.toLowerCase();
            const lines = faqContent.split('\n');
            const matchingLines = [];
            let context = [];
            for (let i = 0; i < lines.length; i++) {
                const line = lines[i];
                if (line.toLowerCase().includes(searchTerm)) {
                    // Add context (previous and next few lines)
                    const start = Math.max(0, i - 2);
                    const end = Math.min(lines.length, i + 3);
                    context = lines.slice(start, end);
                    matchingLines.push(...context, '---', '');
                }
            }
            if (matchingLines.length > 0) {
                console.log(colors_1.chalk.cyan.bold(`🔍 FAQ Search Results for "${options.search}":`));
                console.log();
                console.log(matchingLines.join('\n'));
            }
            else {
                console.log(championship_style_1.FAF_COLORS.fafOrange(`🔍 No results found for "${options.search}"`));
                console.log(colors_1.chalk.dim('💡 Try searching for: spacebar, commands, menu, mode, toggle'));
            }
        }
        else {
            // Show full FAQ
            console.log(colors_1.chalk.cyan.bold('🩵 FAF CLI - Frequently Asked Questions'));
            console.log();
            // Process and display FAQ content with syntax highlighting
            const processedContent = faqContent
                .replace(/^# /gm, colors_1.chalk.cyan.bold('# '))
                .replace(/^## /gm, colors_1.chalk.cyan('## '))
                .replace(/^### /gm, championship_style_1.FAF_COLORS.fafOrange('### '))
                .replace(/\*\*([^*]+)\*\*/g, colors_1.chalk.bold('$1'))
                .replace(/`([^`]+)`/g, colors_1.chalk.gray('`') + colors_1.chalk.cyan('$1') + colors_1.chalk.gray('`'))
                .replace(/```bash\n([\s\S]*?)```/g, (match, code) => {
                return colors_1.chalk.gray('```bash\n') + colors_1.chalk.green(code) + colors_1.chalk.gray('```');
            });
            console.log(processedContent);
        }
        console.log();
        console.log(colors_1.chalk.dim('💡 Use `faf faq --search <term>` to search for specific topics'));
        console.log();
    }
    catch (error) {
        console.error(colors_1.chalk.red('❌ Error displaying FAQ:'), error);
        process.exit(1);
    }
}
//# sourceMappingURL=faq.js.map