import { PMOCommand, pmoBaseFlags } from '../../lib/pmo/index.js';
import { shouldOutputJson } from '../../lib/prompt-json.js';
import { FlagResolver } from '../../lib/flags/index.js';
export default class Spec extends PMOCommand {
    static description = 'Interactive menu for spec operations';
    static examples = [
        '<%= config.bin %> <%= command.id %>',
    ];
    static flags = {
        ...pmoBaseFlags,
    };
    getPMOOptions() {
        return { promptIfMultiple: false };
    }
    async execute() {
        const { flags } = await this.parse(Spec);
        // Check if JSON output mode is active
        const jsonMode = shouldOutputJson(flags);
        // Define choices for the menu
        const menuChoices = [
            { name: 'Create new spec', value: 'create' },
            { name: 'List all specs', value: 'list' },
            { name: 'View spec', value: 'view' },
            { name: 'Delete spec', value: 'delete' },
            { name: 'Generate tickets from spec', value: 'generate' },
            { name: 'Assign ticket to spec', value: 'ticket' },
            { name: 'Manage dependencies', value: 'link' },
            { name: 'Cancel', value: 'cancel' },
        ];
        // Use FlagResolver for action selection
        const resolver = new FlagResolver({
            commandName: 'spec',
            baseCommand: 'prlt spec',
            jsonMode,
            flags: {},
        });
        resolver.addPrompt({
            flagName: 'action',
            type: 'list',
            message: '📄 Spec Operations - What would you like to do?',
            choices: () => menuChoices,
            // Custom command builder for menu items
            getCommand: (value) => {
                const commands = {
                    create: 'prlt spec create --json',
                    list: 'prlt spec list --json',
                    view: 'prlt spec view --json',
                    delete: 'prlt spec delete --json',
                    generate: 'prlt spec plan --json',
                    ticket: 'prlt spec ticket --json',
                    link: 'prlt link list --json',
                    cancel: '',
                };
                return commands[value] || '';
            },
        });
        const resolved = await resolver.resolve();
        const action = resolved.action;
        if (action === 'cancel' || !action) {
            return;
        }
        // Run the selected subcommand
        switch (action) {
            case 'create':
                await this.config.runCommand('spec:create', []);
                break;
            case 'list':
                await this.config.runCommand('spec:list', []);
                break;
            case 'view':
                await this.config.runCommand('spec:view', []);
                break;
            case 'delete':
                await this.config.runCommand('spec:delete', []);
                break;
            case 'generate':
                await this.config.runCommand('spec:generate-tickets', []);
                break;
            case 'ticket':
                await this.config.runCommand('spec:ticket', []);
                break;
            case 'link':
                await this.config.runCommand('link', []);
                break;
        }
    }
}
//# sourceMappingURL=index.js.map