"use strict";
/**
 * 🏆 FAF CONVERT Command
 * Golden Rule: .faf = YAML → Convert to MD or TXT
 */
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;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertCommand = convertCommand;
exports.toMarkdown = toMarkdown;
exports.toText = toText;
const colors_1 = require("../fix-once/colors");
const faf_converters_1 = require("../converters/faf-converters");
const path = __importStar(require("path"));
const fs = __importStar(require("fs"));
async function convertCommand(fafPath, options = {}) {
    console.log(colors_1.chalk.cyan('🔄 FAF Converter - Golden Rule Edition'));
    console.log(colors_1.chalk.gray('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n'));
    try {
        // Find .faf file
        const targetPath = fafPath || '.faf';
        const resolvedPath = path.resolve(targetPath);
        if (!fs.existsSync(resolvedPath)) {
            console.error(colors_1.chalk.red('❌ No .faf file found!'));
            console.log(colors_1.chalk.yellow('💡 Run "faf init" first to create a .faf file'));
            return;
        }
        const format = options.format || 'md';
        console.log(colors_1.chalk.blue(`📝 Converting to ${format.toUpperCase()}...`));
        if (options.save) {
            // Save to file
            const outputPath = (0, faf_converters_1.saveConversion)(resolvedPath, format);
            console.log(colors_1.chalk.green(`✅ Saved to: ${outputPath}`));
            // Show preview
            const content = fs.readFileSync(outputPath, 'utf-8');
            console.log(colors_1.chalk.gray('\n--- Preview ---'));
            console.log(content.substring(0, 500) + '...');
        }
        else {
            // Output to console
            const converted = (0, faf_converters_1.convertFaf)(resolvedPath, options);
            console.log(colors_1.chalk.gray('\n--- Output ---'));
            console.log(converted);
        }
        console.log(colors_1.chalk.gray('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
        console.log(colors_1.chalk.cyan('🏁 Conversion Complete!'));
        if (!options.save) {
            console.log(colors_1.chalk.gray('💡 Use --save to write to file'));
        }
    }
    catch (error) {
        console.error(colors_1.chalk.red(`❌ Conversion failed: ${error.message}`));
        process.exit(1);
    }
}
/**
 * Quick MD converter
 */
async function toMarkdown(fafPath) {
    return convertCommand(fafPath, { format: 'md' });
}
/**
 * Quick TXT converter
 */
async function toText(fafPath) {
    return convertCommand(fafPath, { format: 'txt' });
}
//# sourceMappingURL=convert.js.map