"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.listCommand = listCommand;
const chalk_1 = __importDefault(require("chalk"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const module_system_1 = require("../utils/module-system");
async function listCommand(options) {
    try {
        const modules = await getModules(options.linked);
        if (options.json) {
            console.log(JSON.stringify(modules, null, 2));
            return;
        }
        if (modules.length === 0) {
            console.log(chalk_1.default.yellow(options.linked ? 'No linked modules found.' : 'No modules available.'));
            return;
        }
        console.log(chalk_1.default.bold.blue(`\n${options.linked ? 'Linked' : 'Available'} Modules:\n`));
        modules.forEach((module) => {
            const status = module.linked ? chalk_1.default.green('✓') : chalk_1.default.gray('○');
            console.log(`${status} ${chalk_1.default.bold(module.name)} ${chalk_1.default.gray(`(v${module.version})`)}`);
            console.log(`  ${chalk_1.default.gray(module.description)}`);
            console.log(`  ${chalk_1.default.cyan(`Type: ${module.type}`)}\n`);
        });
        console.log(chalk_1.default.gray(`Total: ${modules.length} module(s)\n`));
    }
    catch (error) {
        console.error(chalk_1.default.red('Error listing modules:'), error);
        process.exit(1);
    }
}
async function getModules(linkedOnly = false) {
    const modules = [];
    // Check for linked modules in current project
    const linkedModules = getLinkedModules();
    if (linkedOnly) {
        return linkedModules;
    }
    // Get all available modules using the module system
    const discoveredModules = (0, module_system_1.discoverModules)();
    for (const module of discoveredModules) {
        modules.push({
            name: module.fullName,
            version: module.metadata.version,
            description: module.metadata.description,
            type: module.metadata.type,
            linked: linkedModules.some(m => m.name === module.fullName)
        });
    }
    return modules;
}
function getLinkedModules() {
    const configPath = path.join(process.cwd(), '.augment', 'extensions.json');
    if (!fs.existsSync(configPath)) {
        return [];
    }
    try {
        const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
        return (config.modules || []).map((m) => ({
            ...m,
            linked: true
        }));
    }
    catch (error) {
        return [];
    }
}
//# sourceMappingURL=list.js.map