import { Flags } from '@oclif/core';
import { PMOCommand, pmoBaseFlags } from '../../lib/pmo/index.js';
import { styles } from '../../lib/styles.js';
import { STATE_CATEGORY_ORDER } from '../../lib/pmo/types.js';
import { isMachineOutput } from '../../lib/prompt-json.js';
export default class PhaseList extends PMOCommand {
    static description = 'List all project lifecycle phases';
    static examples = [
        '<%= config.bin %> <%= command.id %>',
        '<%= config.bin %> <%= command.id %> --category started',
        '<%= config.bin %> <%= command.id %> --machine',
        '<%= config.bin %> <%= command.id %> --json',
    ];
    static flags = {
        ...pmoBaseFlags,
        category: Flags.string({
            char: 'c',
            description: 'Filter by category',
            options: ['backlog', 'unstarted', 'started', 'completed', 'canceled'],
        }),
    };
    async execute() {
        const { flags } = await this.parse(PhaseList);
        const phases = await this.storage.listPhases(flags.category ? { category: flags.category } : undefined);
        if (isMachineOutput(flags)) {
            this.log(JSON.stringify(phases, null, 2));
            return;
        }
        if (phases.length === 0) {
            this.log(styles.muted('\nNo phases found.'));
            return;
        }
        // Group by category
        const grouped = this.groupByCategory(phases);
        this.log(`\n📊 ${styles.emphasis('Project Lifecycle Phases')}`);
        this.log('═'.repeat(60));
        const categoryEmoji = {
            triage: '📬',
            backlog: '📥',
            unstarted: '📋',
            started: '🚀',
            completed: '✅',
            canceled: '🚫',
        };
        for (const category of STATE_CATEGORY_ORDER) {
            if (flags.category && flags.category !== category)
                continue;
            const categoryPhases = grouped.get(category);
            if (!categoryPhases || categoryPhases.length === 0)
                continue;
            const emoji = categoryEmoji[category];
            this.log(`\n${emoji} ${styles.emphasis(category.toUpperCase())}`);
            this.log('─'.repeat(40));
            for (const phase of categoryPhases) {
                const defaultBadge = phase.isDefault ? styles.muted(' (default)') : '';
                const colorPreview = phase.color ? `[${phase.color}]` : '';
                this.log(`  ${phase.name}${defaultBadge} ${styles.muted(colorPreview)}`);
                if (phase.description) {
                    this.log(`    ${styles.muted(phase.description)}`);
                }
            }
        }
        this.log('');
    }
    groupByCategory(phases) {
        const grouped = new Map();
        for (const phase of phases) {
            const existing = grouped.get(phase.category) || [];
            existing.push(phase);
            grouped.set(phase.category, existing);
        }
        return grouped;
    }
}
//# sourceMappingURL=list.js.map