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 { shouldOutputJson } from '../../lib/prompt-json.js';
export default class StatusList extends PMOCommand {
    static description = 'List all workflow statuses for a project';
    static examples = [
        '<%= config.bin %> <%= command.id %>',
        '<%= config.bin %> <%= command.id %> --project my-project',
        '<%= config.bin %> <%= command.id %> --category started',
    ];
    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(StatusList);
        // Check if JSON output mode is active
        const jsonMode = shouldOutputJson(flags);
        // This command requires project context - get projectId (with JSON mode support)
        const projectId = await this.requireProject({
            jsonMode: jsonMode ? {
                flags,
                commandName: 'status list',
                baseCommand: 'prlt status list',
            } : undefined,
        });
        // Get the project's workflow ID
        const project = await this.storage.getProject(projectId);
        if (!project?.workflowId) {
            this.error(`Project "${projectId}" has no workflow assigned.`);
        }
        const allStatuses = await this.storage.listStatuses(project.workflowId);
        // Apply category filter if specified
        const statuses = flags.category
            ? allStatuses.filter(s => s.category === flags.category)
            : allStatuses;
        if (jsonMode) {
            this.log(JSON.stringify(statuses, null, 2));
            return;
        }
        if (statuses.length === 0) {
            this.log(styles.muted('\nNo statuses found.'));
            this.log(styles.muted('Apply a template: prlt template apply kanban'));
            return;
        }
        // Group by category
        const grouped = this.groupByCategory(statuses);
        const projectName = await this.getProjectName(projectId);
        this.log(`\n📊 ${styles.emphasis('Workflow Statuses')} - ${projectName}`);
        this.log('═'.repeat(60));
        const categoryEmoji = {
            triage: '📬',
            backlog: '📥',
            unstarted: '📋',
            started: '🚀',
            completed: '✅',
            canceled: '🚫',
        };
        for (const category of STATE_CATEGORY_ORDER) {
            const categoryStatuses = grouped.get(category);
            if (!categoryStatuses || categoryStatuses.length === 0)
                continue;
            const emoji = categoryEmoji[category];
            this.log(`\n${emoji} ${styles.emphasis(category.toUpperCase())}`);
            this.log('─'.repeat(40));
            for (const status of categoryStatuses) {
                const defaultBadge = status.isDefault ? styles.muted(' (default)') : '';
                const colorPreview = status.color ? `[${status.color}]` : '';
                this.log(`  ${status.name}${defaultBadge} ${styles.muted(colorPreview)}`);
                if (status.description) {
                    this.log(`    ${styles.muted(status.description)}`);
                }
            }
        }
        this.log('');
    }
    groupByCategory(statuses) {
        const grouped = new Map();
        for (const status of statuses) {
            const existing = grouped.get(status.category) || [];
            existing.push(status);
            grouped.set(status.category, existing);
        }
        return grouped;
    }
}
//# sourceMappingURL=list.js.map