import { Codicon } from '../../../../base/common/codicons.js';
import { KeyChord } from '../../../../base/common/keyCodes.js';
import { isCodeEditor, isDiffEditor } from '../../../../editor/browser/editorBrowser.js';
import { EditorAction2 } from '../../../../editor/browser/editorExtensions.js';
import { EmbeddedDiffEditorWidget } from '../../../../editor/browser/widget/diffEditor/embeddedDiffEditorWidget.js';
import { EmbeddedCodeEditorWidget } from '../../../../editor/browser/widget/codeEditor/embeddedCodeEditorWidget.js';
import { EditorContextKeys } from '../../../../editor/common/editorContextKeys.js';
import { InlineChatController, InlineChatRunOptions } from './inlineChatController.js';
import { ACTION_ACCEPT_CHANGES, CTX_INLINE_CHAT_HAS_PROVIDER, MENU_INLINE_CHAT_WIDGET_STATUS, MENU_INLINE_CHAT_WIDGET_DISCARD, CTX_INLINE_CHAT_EDIT_MODE, CTX_INLINE_CHAT_RESPONSE_TYPES, CTX_INLINE_CHAT_RESPONSE_FOCUSED, CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_HAS_STASHED_SESSION, ACTION_REGENERATE_RESPONSE, CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_EMPTY, CTX_INLINE_CHAT_INNER_CURSOR_FIRST, CTX_INLINE_CHAT_INNER_CURSOR_LAST, CTX_INLINE_CHAT_OUTER_CURSOR_POSITION, CTX_INLINE_CHAT_USER_DID_EDIT, CTX_INLINE_CHAT_DID_EDIT, ACTION_TOGGLE_DIFF, CTX_INLINE_CHAT_CHANGE_HAS_DIFF, CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF, MENU_INLINE_CHAT_WIDGET_FEEDBACK, CTX_INLINE_CHAT_SUPPORT_ISSUE_REPORTING, CTX_INLINE_CHAT_DOCUMENT_CHANGED, MENU_INLINE_CHAT_WIDGET, ACTION_VIEW_IN_CHAT } from '../common/inlineChat.js';
import { localize2WithPath, localizeWithPath } from '../../../../nls.js';
import { MenuId, MenuRegistry } from '../../../../platform/actions/common/actions.js';
import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import '../../../../platform/instantiation/common/instantiation.js';
import { IQuickInputService } from '../../../../platform/quickinput/common/quickInput.js';
import { IEditorService, SIDE_GROUP } from '../../../services/editor/common/editorService.js';
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
import { fromNow } from '../../../../base/common/date.js';
import { IInlineChatSessionService } from './inlineChatSessionService.js';
import { runAccessibilityHelpAction } from '../../chat/browser/actions/chatAccessibilityHelp.js';
import { CONTEXT_ACCESSIBILITY_MODE_ENABLED } from '../../../../platform/accessibility/common/accessibility.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { CommandsRegistry } from '../../../../platform/commands/common/commands.js';
import { AccessibilityHelpAction } from '../../accessibility/browser/accessibleViewActions.js';
import { registerIcon } from '../../../../platform/theme/common/iconRegistry.js';
import { IPreferencesService } from '../../../services/preferences/common/preferences.js';
import { ILogService } from '../../../../platform/log/common/log.js';
import { CONTEXT_RESPONSE, CONTEXT_CHAT_LOCATION, CONTEXT_RESPONSE_DETECTED_AGENT_COMMAND } from '../../chat/common/chatContextKeys.js';
import { ChatAgentLocation } from '../../chat/common/chatAgents.js';
CommandsRegistry.registerCommandAlias('interactiveEditor.start', 'inlineChat.start');
CommandsRegistry.registerCommandAlias('interactive.acceptChanges', ACTION_ACCEPT_CHANGES);
const LOCALIZED_START_INLINE_CHAT_STRING = ( localize2WithPath(
    'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
    'run',
    'Start in Editor'
));
const START_INLINE_CHAT = registerIcon('start-inline-chat', Codicon.sparkle, ( localizeWithPath(
    'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
    'startInlineChat',
    'Icon which spawns the inline chat from the editor toolbar.'
)));
class StartSessionAction extends EditorAction2 {
    constructor() {
        super({
            id: 'inlineChat.start',
            title: LOCALIZED_START_INLINE_CHAT_STRING,
            category: AbstractInlineChatAction.category,
            f1: true,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_HAS_PROVIDER, EditorContextKeys.writable)),
            keybinding: {
                when: EditorContextKeys.focus,
                weight: 200 ,
                primary: 2048  | 39 ,
                secondary: [KeyChord(2048  | 41 , 39 )],
            },
            icon: START_INLINE_CHAT
        });
    }
    runEditorCommand(accessor, editor, ..._args) {
        const ctrl = InlineChatController.get(editor);
        if (!ctrl) {
            return;
        }
        let options;
        const arg = _args[0];
        if (arg && InlineChatRunOptions.isInteractiveEditorOptions(arg)) {
            options = arg;
        }
        InlineChatController.get(editor)?.run({ ...options });
    }
}
class UnstashSessionAction extends EditorAction2 {
    constructor() {
        super({
            id: 'inlineChat.unstash',
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'unstash',
                "Resume Last Dismissed Inline Chat"
            )),
            category: AbstractInlineChatAction.category,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_HAS_STASHED_SESSION, EditorContextKeys.writable)),
            keybinding: {
                weight: 200 ,
                primary: 2048  | 56 ,
            }
        });
    }
    async runEditorCommand(_accessor, editor, ..._args) {
        const ctrl = InlineChatController.get(editor);
        if (ctrl) {
            const session = ctrl.unstashLastSession();
            if (session) {
                ctrl.run({
                    existingSession: session,
                    isUnstashed: true
                });
            }
        }
    }
}
class AbstractInlineChatAction extends EditorAction2 {
    static { this.category = ( localize2WithPath(
        'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
        'cat',
        "Inline Chat"
    )); }
    constructor(desc) {
        super({
            ...desc,
            category: AbstractInlineChatAction.category,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_HAS_PROVIDER, desc.precondition))
        });
    }
    runEditorCommand(accessor, editor, ..._args) {
        const editorService = accessor.get(IEditorService);
        const logService = accessor.get(ILogService);
        let ctrl = InlineChatController.get(editor);
        if (!ctrl) {
            const { activeTextEditorControl } = editorService;
            if (isCodeEditor(activeTextEditorControl)) {
                editor = activeTextEditorControl;
            }
            else if (isDiffEditor(activeTextEditorControl)) {
                editor = activeTextEditorControl.getModifiedEditor();
            }
            ctrl = InlineChatController.get(editor);
        }
        if (!ctrl) {
            logService.warn('[IE] NO controller found for action', this.desc.id, editor.getModel()?.uri);
            return;
        }
        if (editor instanceof EmbeddedCodeEditorWidget) {
            editor = editor.getParentEditor();
        }
        if (!ctrl) {
            for (const diffEditor of accessor.get(ICodeEditorService).listDiffEditors()) {
                if (diffEditor.getOriginalEditor() === editor || diffEditor.getModifiedEditor() === editor) {
                    if (diffEditor instanceof EmbeddedDiffEditorWidget) {
                        this.runEditorCommand(accessor, diffEditor.getParentEditor(), ..._args);
                    }
                }
            }
            return;
        }
        this.runInlineChatCommand(accessor, ctrl, editor, ..._args);
    }
}
const CHAT_REGENERATE_MENU = MenuId.for('inlineChat.response.rerun');
MenuRegistry.appendMenuItem(MenuId.ChatMessageTitle, {
    submenu: CHAT_REGENERATE_MENU,
    title: ( localizeWithPath(
        'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
        'reunmenu',
        "Regenerate..."
    )),
    icon: Codicon.refresh,
    group: 'navigation',
    order: -10,
    when: ( ContextKeyExpr.and(CONTEXT_RESPONSE, ( CONTEXT_CHAT_LOCATION.isEqualTo(ChatAgentLocation.Editor))))
});
class ReRunRequestAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: ACTION_REGENERATE_RESPONSE,
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'rerun',
                'Regenerate Response'
            )),
            shortTitle: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'rerunShort',
                'Regenerate'
            )),
            icon: Codicon.refresh,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, ( CTX_INLINE_CHAT_EMPTY.negate()), ( CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo("empty" )))),
            menu: [{
                    id: CHAT_REGENERATE_MENU,
                    group: 'navigation',
                    order: -120,
                    when: ( ContextKeyExpr.and(CONTEXT_RESPONSE, ( CONTEXT_CHAT_LOCATION.isEqualTo(ChatAgentLocation.Editor))))
                }]
        });
    }
    runInlineChatCommand(_accessor, ctrl) {
        ctrl.rerun({ retry: true });
    }
}
class ReRunRequestWithIntentDetectionAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.rerunWithIntentDetection',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'rerunWithout',
                'Regenerate without Command Detection'
            )),
            icon: Codicon.debugRestartFrame,
            menu: {
                id: CHAT_REGENERATE_MENU,
                group: 'navigation',
                order: -100,
                when: ( ContextKeyExpr.and(CONTEXT_RESPONSE_DETECTED_AGENT_COMMAND, CONTEXT_RESPONSE, ( CONTEXT_CHAT_LOCATION.isEqualTo(ChatAgentLocation.Editor))))
            }
        });
    }
    runInlineChatCommand(_accessor, ctrl) {
        ctrl.rerun({ withoutIntentDetection: true });
    }
}
class ArrowOutUpAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.arrowOutUp',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'arrowUp',
                'Cursor Up'
            )),
            precondition: ( ContextKeyExpr.and(
                CTX_INLINE_CHAT_FOCUSED,
                CTX_INLINE_CHAT_INNER_CURSOR_FIRST,
                ( EditorContextKeys.isEmbeddedDiffEditor.negate()),
                ( CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate())
            )),
            keybinding: {
                weight: 0 ,
                primary: 2048  | 16
            }
        });
    }
    runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        ctrl.arrowOut(true);
    }
}
class ArrowOutDownAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.arrowOutDown',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'arrowDown',
                'Cursor Down'
            )),
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_FOCUSED, CTX_INLINE_CHAT_INNER_CURSOR_LAST, ( EditorContextKeys.isEmbeddedDiffEditor.negate()), ( CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()))),
            keybinding: {
                weight: 0 ,
                primary: 2048  | 18
            }
        });
    }
    runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        ctrl.arrowOut(false);
    }
}
class FocusInlineChat extends EditorAction2 {
    constructor() {
        super({
            id: 'inlineChat.focus',
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'focus',
                "Focus Input"
            )),
            f1: true,
            category: AbstractInlineChatAction.category,
            precondition: ( ContextKeyExpr.and(EditorContextKeys.editorTextFocus, CTX_INLINE_CHAT_VISIBLE, ( CTX_INLINE_CHAT_FOCUSED.negate()), ( CONTEXT_ACCESSIBILITY_MODE_ENABLED.negate()))),
            keybinding: [{
                    weight: 0  + 10,
                    when: ( ContextKeyExpr.and(( CTX_INLINE_CHAT_OUTER_CURSOR_POSITION.isEqualTo('above')), ( EditorContextKeys.isEmbeddedDiffEditor.negate()))),
                    primary: 2048  | 18 ,
                }, {
                    weight: 0  + 10,
                    when: ( ContextKeyExpr.and(( CTX_INLINE_CHAT_OUTER_CURSOR_POSITION.isEqualTo('below')), ( EditorContextKeys.isEmbeddedDiffEditor.negate()))),
                    primary: 2048  | 16 ,
                }]
        });
    }
    runEditorCommand(_accessor, editor, ..._args) {
        InlineChatController.get(editor)?.focus();
    }
}
class DiscardHunkAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.discardHunkChange',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'discard',
                'Discard'
            )),
            icon: Codicon.clearAll,
            precondition: CTX_INLINE_CHAT_VISIBLE,
            menu: {
                id: MENU_INLINE_CHAT_WIDGET_STATUS,
                when: ( ContextKeyExpr.and(( CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo("onlyMessages" )), ( CTX_INLINE_CHAT_EDIT_MODE.isEqualTo("live" )))),
                group: '0_main',
                order: 3
            }
        });
    }
    async runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        return ctrl.discardHunk();
    }
}
MenuRegistry.appendMenuItem(MENU_INLINE_CHAT_WIDGET_STATUS, {
    submenu: MENU_INLINE_CHAT_WIDGET_DISCARD,
    title: ( localizeWithPath(
        'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
        'discardMenu',
        "Discard..."
    )),
    icon: Codicon.discard,
    group: '0_main',
    order: 2,
    when: ( ContextKeyExpr.and(( CTX_INLINE_CHAT_EDIT_MODE.notEqualsTo("preview" )), ( CTX_INLINE_CHAT_EDIT_MODE.notEqualsTo("live" )), ( CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo("onlyMessages" )))),
    rememberDefaultAction: true
});
class DiscardAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.discard',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'discard',
                'Discard'
            )),
            icon: Codicon.discard,
            precondition: CTX_INLINE_CHAT_VISIBLE,
            keybinding: {
                weight: 100  - 1,
                primary: 9 ,
                when: ( CTX_INLINE_CHAT_USER_DID_EDIT.negate())
            },
            menu: {
                id: MENU_INLINE_CHAT_WIDGET_DISCARD,
                group: '0_main',
                order: 0
            }
        });
    }
    async runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        await ctrl.cancelSession();
    }
}
class DiscardToClipboardAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.discardToClipboard',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'undo.clipboard',
                'Discard to Clipboard'
            )),
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_DID_EDIT)),
            menu: {
                id: MENU_INLINE_CHAT_WIDGET_DISCARD,
                group: '0_main',
                order: 1
            }
        });
    }
    async runInlineChatCommand(accessor, ctrl) {
        const clipboardService = accessor.get(IClipboardService);
        const changedText = await ctrl.cancelSession();
        if (changedText !== undefined) {
            clipboardService.writeText(changedText);
        }
    }
}
class DiscardUndoToNewFileAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.discardToFile',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'undo.newfile',
                'Discard to New File'
            )),
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, CTX_INLINE_CHAT_DID_EDIT)),
            menu: {
                id: MENU_INLINE_CHAT_WIDGET_DISCARD,
                group: '0_main',
                order: 2
            }
        });
    }
    async runInlineChatCommand(accessor, ctrl, editor, ..._args) {
        const editorService = accessor.get(IEditorService);
        const changedText = await ctrl.cancelSession();
        if (changedText !== undefined) {
            const input = { forceUntitled: true, resource: undefined, contents: changedText, languageId: editor.getModel()?.getLanguageId() };
            editorService.openEditor(input, SIDE_GROUP);
        }
    }
}
class ToggleDiffForChange extends AbstractInlineChatAction {
    constructor() {
        super({
            id: ACTION_TOGGLE_DIFF,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, ( CTX_INLINE_CHAT_EDIT_MODE.isEqualTo("live" )), CTX_INLINE_CHAT_CHANGE_HAS_DIFF)),
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'showChanges',
                'Toggle Changes'
            )),
            icon: Codicon.diffSingle,
            toggled: {
                condition: CTX_INLINE_CHAT_CHANGE_SHOWS_DIFF,
            },
            menu: [
                {
                    id: MENU_INLINE_CHAT_WIDGET_STATUS,
                    group: '1_main',
                    when: ( ContextKeyExpr.and(( CTX_INLINE_CHAT_EDIT_MODE.isEqualTo("live" )), CTX_INLINE_CHAT_CHANGE_HAS_DIFF))
                }
            ]
        });
    }
    runInlineChatCommand(accessor, ctrl) {
        ctrl.toggleDiff();
    }
}
class ReportIssueForBugCommand extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.reportIssueForBug',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'feedback.reportIssueForBug',
                'Report Issue'
            )),
            icon: Codicon.report,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, ( CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo("empty" )))),
            menu: [{
                    id: MENU_INLINE_CHAT_WIDGET_FEEDBACK,
                    when: ( ContextKeyExpr.and(CTX_INLINE_CHAT_SUPPORT_ISSUE_REPORTING, ( CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo("empty" )))),
                    group: '2_feedback',
                    order: 3
                }]
        });
    }
    runInlineChatCommand(_accessor, ctrl) {
        ctrl.feedbackLast(4 );
    }
}
class AcceptChanges extends AbstractInlineChatAction {
    constructor() {
        super({
            id: ACTION_ACCEPT_CHANGES,
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'apply1',
                "Accept Changes"
            )),
            shortTitle: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'apply2',
                'Accept'
            )),
            icon: Codicon.check,
            f1: true,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, ( ContextKeyExpr.or(( CTX_INLINE_CHAT_DOCUMENT_CHANGED.toNegated()), ( CTX_INLINE_CHAT_EDIT_MODE.notEqualsTo("preview" )))))),
            keybinding: [{
                    weight: 200  + 10,
                    primary: 2048  | 3 ,
                }],
            menu: {
                when: ( ContextKeyExpr.and(( CTX_INLINE_CHAT_RESPONSE_TYPES.notEqualsTo("onlyMessages" )))),
                id: MENU_INLINE_CHAT_WIDGET_STATUS,
                group: '0_main',
                order: 0
            }
        });
    }
    async runInlineChatCommand(_accessor, ctrl) {
        ctrl.acceptHunk();
    }
}
class CancelSessionAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.cancel',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'cancel',
                'Cancel'
            )),
            icon: Codicon.clearAll,
            precondition: ( ContextKeyExpr.and(CTX_INLINE_CHAT_VISIBLE, ( CTX_INLINE_CHAT_EDIT_MODE.isEqualTo("preview" )))),
            keybinding: {
                weight: 100  - 1,
                primary: 9
            },
            menu: {
                id: MENU_INLINE_CHAT_WIDGET_STATUS,
                when: ( CTX_INLINE_CHAT_EDIT_MODE.isEqualTo("preview" )),
                group: '0_main',
                order: 3
            }
        });
    }
    async runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        ctrl.cancelSession();
    }
}
class CloseAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.close',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'close',
                'Close'
            )),
            icon: Codicon.close,
            precondition: CTX_INLINE_CHAT_VISIBLE,
            keybinding: {
                weight: 100  - 1,
                primary: 9 ,
                when: ( CTX_INLINE_CHAT_USER_DID_EDIT.negate())
            },
            menu: {
                id: MENU_INLINE_CHAT_WIDGET,
                group: 'navigation',
                order: 10,
            }
        });
    }
    async runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        ctrl.cancelSession();
    }
}
class ConfigureInlineChatAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.configure',
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'configure',
                'Configure '
            )),
            icon: Codicon.settingsGear,
            precondition: CTX_INLINE_CHAT_VISIBLE,
            menu: {
                id: MENU_INLINE_CHAT_WIDGET,
                group: 'config',
                order: 1,
            }
        });
    }
    async runInlineChatCommand(accessor, ctrl, _editor, ..._args) {
        accessor.get(IPreferencesService).openSettings({ query: 'inlineChat' });
    }
}
class MoveToNextHunk extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.moveToNextHunk',
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'moveToNextHunk',
                'Move to Next Change'
            )),
            precondition: CTX_INLINE_CHAT_VISIBLE,
            f1: true,
            keybinding: {
                weight: 200 ,
                primary: 65
            }
        });
    }
    runInlineChatCommand(accessor, ctrl, editor, ...args) {
        ctrl.moveHunk(true);
    }
}
class MoveToPreviousHunk extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.moveToPreviousHunk',
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'moveToPreviousHunk',
                'Move to Previous Change'
            )),
            f1: true,
            precondition: CTX_INLINE_CHAT_VISIBLE,
            keybinding: {
                weight: 200 ,
                primary: 1024  | 65
            }
        });
    }
    runInlineChatCommand(accessor, ctrl, editor, ...args) {
        ctrl.moveHunk(false);
    }
}
class CopyRecordings extends AbstractInlineChatAction {
    constructor() {
        super({
            id: 'inlineChat.copyRecordings',
            f1: true,
            title: ( localize2WithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'copyRecordings',
                "(Developer) Write Exchange to Clipboard"
            ))
        });
    }
    async runInlineChatCommand(accessor) {
        const clipboardService = accessor.get(IClipboardService);
        const quickPickService = accessor.get(IQuickInputService);
        const ieSessionService = accessor.get(IInlineChatSessionService);
        const recordings = ieSessionService.recordings().filter(r => r.exchanges.length > 0);
        if (recordings.length === 0) {
            return;
        }
        const picks = ( recordings.map(rec => {
            return {
                rec,
                label: ( localizeWithPath(
                    'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                    'label',
                    "'{0}' and {1} follow ups ({2})",
                    rec.exchanges[0].prompt,
                    rec.exchanges.length - 1,
                    fromNow(rec.when, true)
                )),
                tooltip: ( rec.exchanges.map(ex => ex.prompt)).join('\n'),
            };
        }));
        const pick = await quickPickService.pick(picks, { canPickMany: false });
        if (pick) {
            clipboardService.writeText(JSON.stringify(pick.rec, undefined, 2));
        }
    }
}
class ViewInChatAction extends AbstractInlineChatAction {
    constructor() {
        super({
            id: ACTION_VIEW_IN_CHAT,
            title: ( localizeWithPath(
                'vs/workbench/contrib/inlineChat/browser/inlineChatActions',
                'viewInChat',
                'View in Chat'
            )),
            icon: Codicon.commentDiscussion,
            precondition: CTX_INLINE_CHAT_VISIBLE,
            menu: {
                id: MENU_INLINE_CHAT_WIDGET_STATUS,
                when: ( CTX_INLINE_CHAT_RESPONSE_TYPES.isEqualTo("onlyMessages" )),
                group: '0_main',
                order: 1
            }
        });
    }
    runInlineChatCommand(_accessor, ctrl, _editor, ..._args) {
        ctrl.viewInChat();
    }
}
class InlineAccessibilityHelpContribution extends Disposable {
    constructor() {
        super();
        this._register(AccessibilityHelpAction.addImplementation(106, 'inlineChat', async (accessor) => {
            const codeEditor = accessor.get(ICodeEditorService).getActiveCodeEditor() || accessor.get(ICodeEditorService).getFocusedCodeEditor();
            if (!codeEditor) {
                return;
            }
            runAccessibilityHelpAction(accessor, codeEditor, 'inlineChat');
        }, ( ContextKeyExpr.or(CTX_INLINE_CHAT_RESPONSE_FOCUSED, CTX_INLINE_CHAT_FOCUSED))));
    }
}
export { AbstractInlineChatAction, AcceptChanges, ArrowOutDownAction, ArrowOutUpAction, CancelSessionAction, CloseAction, ConfigureInlineChatAction, CopyRecordings, DiscardAction, DiscardHunkAction, DiscardToClipboardAction, DiscardUndoToNewFileAction, FocusInlineChat, InlineAccessibilityHelpContribution, LOCALIZED_START_INLINE_CHAT_STRING, MoveToNextHunk, MoveToPreviousHunk, ReRunRequestAction, ReRunRequestWithIntentDetectionAction, ReportIssueForBugCommand, START_INLINE_CHAT, StartSessionAction, ToggleDiffForChange, UnstashSessionAction, ViewInChatAction };
