import { Codicon } from '../../../../../base/common/codicons.js';
import { localize2WithPath } from '../../../../../nls.js';
import { Action2, MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js';
import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js';
import { CHAT_CATEGORY } from './chatActions.js';
import { IChatWidgetService } from '../chat.service.js';
import { CONTEXT_CHAT_INPUT_HAS_TEXT, CONTEXT_CHAT_REQUEST_IN_PROGRESS, CONTEXT_IN_CHAT_INPUT } from '../../common/chatContextKeys.js';
import { IChatService } from '../../common/chatService.service.js';
const _moduleId = "vs/workbench/contrib/chat/browser/actions/chatExecuteActions";
class SubmitAction extends Action2 {
    static { this.ID = 'workbench.action.chat.submit'; }
    constructor() {
        super({
            id: SubmitAction.ID,
            title: ( localize2WithPath(_moduleId, 0, "Submit")),
            f1: false,
            category: CHAT_CATEGORY,
            icon: Codicon.send,
            precondition: ( (ContextKeyExpr.and(
                CONTEXT_CHAT_INPUT_HAS_TEXT,
                 (CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate())
            ))),
            menu: {
                id: MenuId.ChatExecute,
                when: ( (CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate())),
                group: 'navigation',
            },
        });
    }
    run(accessor, ...args) {
        const context = args[0];
        const widgetService = accessor.get(IChatWidgetService);
        const widget = context?.widget ?? widgetService.lastFocusedWidget;
        widget?.acceptInput(context?.inputValue);
    }
}
class SendToNewChatAction extends Action2 {
    constructor() {
        super({
            id: 'workbench.action.chat.sendToNewChat',
            title: ( localize2WithPath(_moduleId, 1, "Send to New Chat")),
            precondition: ( (ContextKeyExpr.and(
                 (CONTEXT_CHAT_REQUEST_IN_PROGRESS.negate()),
                CONTEXT_CHAT_INPUT_HAS_TEXT
            ))),
            category: CHAT_CATEGORY,
            f1: false,
            menu: {
                id: MenuId.ChatExecuteSecondary,
                group: 'group_2'
            },
            keybinding: {
                weight: 200 ,
                primary: 2048  | 1024  | 3 ,
                when: CONTEXT_IN_CHAT_INPUT,
            }
        });
    }
    async run(accessor, ...args) {
        const context = args[0];
        const widgetService = accessor.get(IChatWidgetService);
        const widget = context?.widget ?? widgetService.lastFocusedWidget;
        if (!widget) {
            return;
        }
        widget.clear();
        widget.acceptInput(context?.inputValue);
    }
}
class CancelAction extends Action2 {
    static { this.ID = 'workbench.action.chat.cancel'; }
    constructor() {
        super({
            id: CancelAction.ID,
            title: ( localize2WithPath(_moduleId, 2, "Cancel")),
            f1: false,
            category: CHAT_CATEGORY,
            icon: Codicon.debugStop,
            menu: {
                id: MenuId.ChatExecute,
                when: CONTEXT_CHAT_REQUEST_IN_PROGRESS,
                group: 'navigation',
            }
        });
    }
    run(accessor, ...args) {
        const context = args[0];
        if (!context.widget) {
            return;
        }
        const chatService = accessor.get(IChatService);
        if (context.widget.viewModel) {
            chatService.cancelCurrentRequestForSession(context.widget.viewModel.sessionId);
        }
    }
}
function registerChatExecuteActions() {
    registerAction2(SubmitAction);
    registerAction2(CancelAction);
    registerAction2(SendToNewChatAction);
}
export { CancelAction, SubmitAction, registerChatExecuteActions };
