import { Flags } from '@oclif/core';
import { PMOCommand, pmoBaseFlags } from '../../lib/pmo/index.js';
import { shouldOutputJson } from '../../lib/prompt-json.js';
import { styles } from '../../lib/styles.js';
export default class CategoryList extends PMOCommand {
    static description = 'List categories for ticket or status types';
    static examples = [
        '<%= config.bin %> <%= command.id %>',
        '<%= config.bin %> <%= command.id %> --type ticket',
        '<%= config.bin %> <%= command.id %> --type status',
        '<%= config.bin %> <%= command.id %> --type ticket --builtin',
        '<%= config.bin %> <%= command.id %> --type ticket --json',
    ];
    static flags = {
        ...pmoBaseFlags,
        type: Flags.string({
            char: 't',
            description: 'Category type to list (omit to list all)',
            options: ['ticket', 'status'],
        }),
        builtin: Flags.boolean({
            description: 'Show only built-in categories',
            exclusive: ['custom'],
        }),
        custom: Flags.boolean({
            description: 'Show only custom categories',
            exclusive: ['builtin'],
        }),
        json: Flags.boolean({
            description: 'Output as JSON',
            default: false,
        }),
    };
    getPMOOptions() {
        return { promptIfMultiple: false };
    }
    async execute() {
        const { flags } = await this.parse(CategoryList);
        const categoryType = flags.type;
        const filter = {};
        if (categoryType)
            filter.type = categoryType;
        if (flags.builtin)
            filter.isBuiltin = true;
        if (flags.custom)
            filter.isBuiltin = false;
        const categories = await this.storage.listCategories(filter);
        if (shouldOutputJson(flags)) {
            this.log(JSON.stringify(categories, null, 2));
            return;
        }
        if (categories.length === 0) {
            const typeStr = categoryType ? `${categoryType} ` : '';
            this.log(styles.muted(`\nNo ${typeStr}categories found.`));
            this.log(styles.muted(`Create one: prlt category create --type ticket`));
            return;
        }
        if (categoryType) {
            // Single type: show as before
            const typeLabel = categoryType === 'ticket' ? 'Ticket' : 'Status';
            this.log(`\n📁 ${styles.emphasis(`${typeLabel} Categories`)}`);
            this.log('═'.repeat(60));
            this.printCategoryGroup(categories, flags);
            this.log('');
            this.log(styles.muted(`Create new: prlt category create --type ${categoryType} <name>`));
            this.log('');
        }
        else {
            // All types: group by type
            const ticketCategories = categories.filter(c => c.type === 'ticket');
            const statusCategories = categories.filter(c => c.type === 'status');
            if (ticketCategories.length > 0) {
                this.log(`\n📁 ${styles.emphasis('Ticket Categories')}`);
                this.log('═'.repeat(60));
                this.printCategoryGroup(ticketCategories, flags);
            }
            if (statusCategories.length > 0) {
                this.log(`\n📁 ${styles.emphasis('Status Categories')}`);
                this.log('═'.repeat(60));
                this.printCategoryGroup(statusCategories, flags);
            }
            this.log('');
        }
    }
    printCategoryGroup(categories, flags) {
        const builtinCategories = categories.filter(c => c.isBuiltin);
        const customCategories = categories.filter(c => !c.isBuiltin);
        if (builtinCategories.length > 0 && !flags.custom) {
            this.log(`\n${styles.emphasis('Built-in Categories')}`);
            this.log('─'.repeat(40));
            for (const category of builtinCategories) {
                this.printCategory(category);
            }
        }
        if (customCategories.length > 0 && !flags.builtin) {
            this.log(`\n${styles.emphasis('Custom Categories')}`);
            this.log('─'.repeat(40));
            for (const category of customCategories) {
                this.printCategory(category);
            }
        }
    }
    printCategory(category) {
        const builtinBadge = category.isBuiltin ? '' : ' [custom]';
        this.log(`  ${styles.emphasis(category.name)} ${styles.muted(`(${category.id})`)}${builtinBadge}`);
        if (category.description) {
            this.log(`    ${styles.muted(category.description)}`);
        }
    }
}
//# sourceMappingURL=list.js.map