/**
 * @license
 * Copyright 2026 HopCode Team
 * SPDX-License-Identifier: Apache-2.0
 */
import { CommandKind } from './types.js';
import { t } from '../../i18n/index.js';
import { APPROVAL_MODES } from '@hoptrendy/hopcode-core';
/**
 * Parses the argument string and returns the corresponding ApprovalMode if valid.
 * Returns undefined if the argument is empty or not a valid mode.
 */
function parseApprovalModeArg(arg) {
    const trimmed = arg.trim().toLowerCase();
    if (!trimmed) {
        return undefined;
    }
    // Match against valid approval modes (case-insensitive)
    return APPROVAL_MODES.find((mode) => mode.toLowerCase() === trimmed);
}
export const approvalModeCommand = {
    name: 'approval-mode',
    get description() {
        return t('View or change the approval mode for tool usage');
    },
    argumentHint: '<mode>',
    kind: CommandKind.BUILT_IN,
    supportedModes: ['interactive'],
    action: async (context, args) => {
        const mode = parseApprovalModeArg(args);
        // If no argument provided, open dialog in interactive mode;
        // in non-interactive/ACP, return current state instead
        if (!args.trim()) {
            return {
                type: 'dialog',
                dialog: 'approval-mode',
            };
        }
        // If invalid argument, return error message with valid options
        if (!mode) {
            return {
                type: 'message',
                messageType: 'error',
                content: t('Invalid approval mode "{{arg}}". Valid modes: {{modes}}', {
                    arg: args.trim(),
                    modes: APPROVAL_MODES.join(', '),
                }),
            };
        }
        // Set the mode for current session only (not persisted)
        const { config } = context.services;
        if (config) {
            try {
                config.setApprovalMode(mode);
            }
            catch (e) {
                return {
                    type: 'message',
                    messageType: 'error',
                    content: e.message,
                };
            }
        }
        return {
            type: 'message',
            messageType: 'info',
            content: t('Approval mode set to "{{mode}}"', { mode }),
        };
    },
};
//# sourceMappingURL=approvalModeCommand.js.map