import { Codicon } from '../../../../../base/common/codicons.js';
import { KeyMod as KeyMod$1, KeyCode } from '../../../../../base/common/keyCodes.js';
import { ICodeEditorService } from '../../../../../editor/browser/services/codeEditorService.js';
import { Selection } from '../../../../../editor/common/core/selection.js';
import { localize2WithPath, localizeWithPath } from '../../../../../nls.js';
import { registerAction2, Action2, MenuId } from '../../../../../platform/actions/common/actions.js';
import { KeybindingWeight } from '../../../../../platform/keybinding/common/keybindingsRegistry.js';
import { CHAT_CATEGORY } from './chatActions.js';
import { IQuickChatService } from '../chat.service.js';
import { CONTEXT_CHAT_ENABLED } from '../../common/chatContextKeys.js';
import { InlineChatController } from '../../../inlineChat/browser/inlineChatController.js';
const _moduleId = "vs/workbench/contrib/chat/browser/actions/chatQuickInputActions";
const ASK_QUICK_QUESTION_ACTION_ID = 'workbench.action.quickchat.toggle';
function registerQuickChatActions() {
    registerAction2(QuickChatGlobalAction);
    registerAction2(AskQuickChatAction);
    registerAction2(class OpenInChatViewAction extends Action2 {
        constructor() {
            super({
                id: 'workbench.action.quickchat.openInChatView',
                title: ( localize2WithPath(_moduleId, 0, "Open in Chat View")),
                f1: false,
                category: CHAT_CATEGORY,
                icon: Codicon.commentDiscussion,
                menu: {
                    id: MenuId.ChatInputSide,
                    group: 'navigation',
                    order: 10
                }
            });
        }
        run(accessor) {
            const quickChatService = accessor.get(IQuickChatService);
            quickChatService.openInChatView();
        }
    });
    registerAction2(class CloseQuickChatAction extends Action2 {
        constructor() {
            super({
                id: 'workbench.action.quickchat.close',
                title: ( localize2WithPath(_moduleId, 1, "Close Quick Chat")),
                f1: false,
                category: CHAT_CATEGORY,
                icon: Codicon.close,
                menu: {
                    id: MenuId.ChatInputSide,
                    group: 'navigation',
                    order: 20
                }
            });
        }
        run(accessor) {
            const quickChatService = accessor.get(IQuickChatService);
            quickChatService.close();
        }
    });
    registerAction2(class LaunchInlineChatFromQuickChatAction extends Action2 {
        constructor() {
            super({
                id: 'workbench.action.quickchat.launchInlineChat',
                title: ( localize2WithPath(_moduleId, 2, "Launch Inline Chat")),
                f1: false,
                category: CHAT_CATEGORY
            });
        }
        async run(accessor) {
            const quickChatService = accessor.get(IQuickChatService);
            const codeEditorService = accessor.get(ICodeEditorService);
            if (quickChatService.focused) {
                quickChatService.close();
            }
            const codeEditor = codeEditorService.getActiveCodeEditor();
            if (!codeEditor) {
                return;
            }
            const controller = InlineChatController.get(codeEditor);
            if (!controller) {
                return;
            }
            await controller.run();
            controller.focus();
        }
    });
}
class QuickChatGlobalAction extends Action2 {
    constructor() {
        super({
            id: ASK_QUICK_QUESTION_ACTION_ID,
            title: ( localize2WithPath(_moduleId, 3, 'Quick Chat')),
            precondition: CONTEXT_CHAT_ENABLED,
            icon: Codicon.commentDiscussion,
            f1: false,
            category: CHAT_CATEGORY,
            keybinding: {
                weight: KeybindingWeight.WorkbenchContrib,
                primary: KeyMod$1.CtrlCmd | KeyMod$1.Shift | KeyCode.KeyI,
                linux: {
                    primary: KeyMod$1.CtrlCmd | KeyMod$1.Shift | KeyMod$1.Alt | KeyCode.KeyI
                }
            },
            metadata: {
                description: ( localizeWithPath(_moduleId, 4, 'Toggle the quick chat')),
                args: [{
                        name: 'args',
                        schema: {
                            anyOf: [
                                {
                                    type: 'object',
                                    required: ['query'],
                                    properties: {
                                        query: {
                                            description: ( localizeWithPath(_moduleId, 5, "The query to open the quick chat with")),
                                            type: 'string'
                                        },
                                        isPartialQuery: {
                                            description: ( localizeWithPath(
                                                _moduleId,
                                                6,
                                                "Whether the query is partial; it will wait for more user input"
                                            )),
                                            type: 'boolean'
                                        }
                                    },
                                },
                                {
                                    type: 'string',
                                    description: ( localizeWithPath(_moduleId, 5, "The query to open the quick chat with"))
                                }
                            ]
                        }
                    }]
            },
        });
    }
    run(accessor, query) {
        const quickChatService = accessor.get(IQuickChatService);
        let options;
        switch (typeof query) {
            case 'string':
                options = { query };
                break;
            case 'object':
                options = query;
                break;
        }
        if (options?.query) {
            options.selection = ( (new Selection(1, options.query.length + 1, 1, options.query.length + 1)));
        }
        quickChatService.toggle(options);
    }
}
class AskQuickChatAction extends Action2 {
    constructor() {
        super({
            id: `workbench.action.openQuickChat`,
            category: CHAT_CATEGORY,
            title: ( localize2WithPath(_moduleId, 7, "Open Quick Chat")),
            f1: true
        });
    }
    run(accessor, query) {
        const quickChatService = accessor.get(IQuickChatService);
        quickChatService.toggle(query ? {
            query,
            selection: ( (new Selection(1, query.length + 1, 1, query.length + 1)))
        } : undefined);
    }
}
export { ASK_QUICK_QUESTION_ACTION_ID, registerQuickChatActions };
