/* eslint-disable no-console */
/**
 * Templates command - list available templates
 */
import { nodeTemplates, getAllWorkflowTemplates } from "../templates/index.js";
import { loadPackTemplates } from "../templates/pack-loader.js";
import { logger } from "../utils/logger.js";
export async function templatesCommand(options = {}) {
    const { json = false } = options;
    // Load pack-contributed templates so they appear alongside core templates
    await loadPackTemplates(process.cwd());
    const allWorkflowTemplates = getAllWorkflowTemplates();
    if (json) {
        console.log(JSON.stringify({
            workflows: allWorkflowTemplates.map((t) => ({
                id: t.id,
                name: t.name,
                description: t.description,
                category: t.category,
            })),
            nodes: nodeTemplates.map((t) => ({
                id: t.id,
                name: t.name,
                description: t.description,
            })),
        }, null, 2));
        return;
    }
    logger.section("Workflow Templates");
    logger.newline();
    // Group by category
    const categories = new Map();
    for (const template of allWorkflowTemplates) {
        const cat = template.category;
        if (!categories.has(cat)) {
            categories.set(cat, []);
        }
        categories.get(cat).push(template);
    }
    for (const [category, templates] of categories) {
        logger.info(`  ${category}:`);
        for (const t of templates) {
            logger.log(`    ${t.id.padEnd(15)} ${t.description}`);
        }
        logger.newline();
    }
    logger.section("Node Templates");
    logger.newline();
    for (const t of nodeTemplates) {
        logger.log(`  ${t.id.padEnd(15)} ${t.description}`);
    }
    logger.newline();
    logger.section("Usage");
    logger.log("  $ fw create workflow <template> <file> [--async] [--line N]");
    logger.log("  $ fw create node <name> <file> [-t <template>] [--line N]");
    logger.newline();
}
//# sourceMappingURL=templates.js.map