"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.doCommunity = doCommunity;
const utils_1 = require("../utils");
const cloud_1 = require("./cloud");
function doCommunity(args) {
    (0, utils_1.printHeader)('Cell Community');
    const sub = args[1] || 'stats';
    // Route to cloud-based community packs if available
    if (sub === 'list' || sub === 'show' || sub === 'install') {
        (0, cloud_1.doCommunityPacks)(args);
        return;
    }
    if (sub === 'stats') {
        (0, utils_1.httpGet)('/community/v2/stats').then((result) => {
            console.log(utils_1.C.bold('  Community Stats:'));
            console.log(`    Patterns: ${result.totalPatterns || 0}`);
            console.log(`    Insights: ${result.totalInsights || 0}`);
            console.log(`    Benchmarks: ${result.totalBenchmarks || 0}`);
        }).catch(() => (0, utils_1.printWarning)('Failed to get community stats'));
        return;
    }
    if (sub === 'patterns') {
        const category = args[2] || '';
        (0, utils_1.httpGet)(`/community/v2/patterns?category=${category}`).then((result) => {
            if (result.patterns && result.patterns.length > 0) {
                for (const p of result.patterns.slice(0, 10)) {
                    console.log(`  [${p.category}] ${p.rule}`);
                    (0, utils_1.printDim)(`    Language: ${p.language} | Votes: ${p.votes}`);
                }
            }
            else {
                (0, utils_1.printDim)('No community patterns found');
            }
        }).catch(() => (0, utils_1.printWarning)('Failed to get patterns'));
        return;
    }
    if (sub === 'trends') {
        (0, utils_1.httpGet)('/community/v2/trends').then((result) => {
            if (result.trends && result.trends.length > 0) {
                for (const t of result.trends.slice(0, 10)) {
                    console.log(`  ${t.technology}: ${t.trend}`);
                }
            }
            else {
                (0, utils_1.printDim)('No trends available');
            }
        }).catch(() => (0, utils_1.printWarning)('Failed to get trends'));
        return;
    }
    if (sub === 'insights') {
        (0, utils_1.httpGet)('/community/v2/insights').then((result) => {
            if (result.insights && result.insights.length > 0) {
                for (const i of result.insights.slice(0, 10)) {
                    console.log(`  [${i.severity}] ${i.title}`);
                    (0, utils_1.printDim)(`    ${i.description}`);
                }
            }
            else {
                (0, utils_1.printDim)('No community insights');
            }
        }).catch(() => (0, utils_1.printWarning)('Failed to get insights'));
        return;
    }
    // Default: show stats
    (0, utils_1.httpGet)('/community/v2/stats').then((result) => {
        console.log(JSON.stringify(result, null, 2));
    }).catch(() => (0, utils_1.printWarning)('Failed to get community info'));
}
//# sourceMappingURL=community.js.map