import { KeyMod as KeyMod$1, KeyCode } from '../../../../base/common/keyCodes.js';
import { transaction, asyncTransaction } from '../../../../base/common/observableInternal/base.js';
import '../../../../base/common/observableInternal/derived.js';
import '../../../../base/common/observableInternal/autorun.js';
import '../../../../base/common/observableInternal/utils.js';
import '../../../../base/common/cancellation.js';
import '../../../../base/common/arrays.js';
import { EditorAction } from '../../../browser/editorExtensions.js';
import { EditorContextKeys } from '../../../common/editorContextKeys.js';
import { showNextInlineSuggestionActionId, showPreviousInlineSuggestionActionId, inlineSuggestCommitId } from './commandIds.js';
import { InlineCompletionContextKeys } from './inlineCompletionContextKeys.js';
import { InlineCompletionsController } from './inlineCompletionsController.js';
import { Context } from '../../suggest/browser/suggest.js';
import { localizeWithPath } from '../../../../nls.js';
import { Action2, MenuId } from '../../../../platform/actions/common/actions.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.service.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
const _moduleId = "vs/editor/contrib/inlineCompletions/browser/commands";
class ShowNextInlineSuggestionAction extends EditorAction {
    static { this.ID = showNextInlineSuggestionActionId; }
    constructor() {
        super({
            id: ShowNextInlineSuggestionAction.ID,
            label: ( localizeWithPath(_moduleId, 0, "Show Next Inline Suggestion")),
            alias: 'Show Next Inline Suggestion',
            precondition: ( (ContextKeyExpr.and(
                EditorContextKeys.writable,
                InlineCompletionContextKeys.inlineSuggestionVisible
            ))),
            kbOpts: {
                weight: 100,
                primary: KeyMod$1.Alt | KeyCode.BracketRight,
            },
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        controller?.model.get()?.next();
    }
}
class ShowPreviousInlineSuggestionAction extends EditorAction {
    static { this.ID = showPreviousInlineSuggestionActionId; }
    constructor() {
        super({
            id: ShowPreviousInlineSuggestionAction.ID,
            label: ( localizeWithPath(_moduleId, 1, "Show Previous Inline Suggestion")),
            alias: 'Show Previous Inline Suggestion',
            precondition: ( (ContextKeyExpr.and(
                EditorContextKeys.writable,
                InlineCompletionContextKeys.inlineSuggestionVisible
            ))),
            kbOpts: {
                weight: 100,
                primary: KeyMod$1.Alt | KeyCode.BracketLeft,
            },
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        controller?.model.get()?.previous();
    }
}
class TriggerInlineSuggestionAction extends EditorAction {
    constructor() {
        super({
            id: 'editor.action.inlineSuggest.trigger',
            label: ( localizeWithPath(_moduleId, 2, "Trigger Inline Suggestion")),
            alias: 'Trigger Inline Suggestion',
            precondition: EditorContextKeys.writable
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        await asyncTransaction(async (tx) => {
            await controller?.model.get()?.triggerExplicitly(tx);
            controller?.playAccessibilitySignal(tx);
        });
    }
}
class AcceptNextWordOfInlineCompletion extends EditorAction {
    constructor() {
        super({
            id: 'editor.action.inlineSuggest.acceptNextWord',
            label: ( localizeWithPath(_moduleId, 3, "Accept Next Word Of Inline Suggestion")),
            alias: 'Accept Next Word Of Inline Suggestion',
            precondition: ( (ContextKeyExpr.and(
                EditorContextKeys.writable,
                InlineCompletionContextKeys.inlineSuggestionVisible
            ))),
            kbOpts: {
                weight: KeybindingWeight.EditorContrib + 1,
                primary: KeyMod$1.CtrlCmd | KeyCode.RightArrow,
                kbExpr: ( (ContextKeyExpr.and(
                    EditorContextKeys.writable,
                    InlineCompletionContextKeys.inlineSuggestionVisible
                ))),
            },
            menuOpts: [{
                    menuId: MenuId.InlineSuggestionToolbar,
                    title: ( localizeWithPath(_moduleId, 4, 'Accept Word')),
                    group: 'primary',
                    order: 2,
                }],
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        await controller?.model.get()?.acceptNextWord(controller.editor);
    }
}
class AcceptNextLineOfInlineCompletion extends EditorAction {
    constructor() {
        super({
            id: 'editor.action.inlineSuggest.acceptNextLine',
            label: ( localizeWithPath(_moduleId, 5, "Accept Next Line Of Inline Suggestion")),
            alias: 'Accept Next Line Of Inline Suggestion',
            precondition: ( (ContextKeyExpr.and(
                EditorContextKeys.writable,
                InlineCompletionContextKeys.inlineSuggestionVisible
            ))),
            kbOpts: {
                weight: KeybindingWeight.EditorContrib + 1,
            },
            menuOpts: [{
                    menuId: MenuId.InlineSuggestionToolbar,
                    title: ( localizeWithPath(_moduleId, 6, 'Accept Line')),
                    group: 'secondary',
                    order: 2,
                }],
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        await controller?.model.get()?.acceptNextLine(controller.editor);
    }
}
class AcceptInlineCompletion extends EditorAction {
    constructor() {
        super({
            id: inlineSuggestCommitId,
            label: ( localizeWithPath(_moduleId, 7, "Accept Inline Suggestion")),
            alias: 'Accept Inline Suggestion',
            precondition: InlineCompletionContextKeys.inlineSuggestionVisible,
            menuOpts: [{
                    menuId: MenuId.InlineSuggestionToolbar,
                    title: ( localizeWithPath(_moduleId, 8, "Accept")),
                    group: 'primary',
                    order: 1,
                }],
            kbOpts: {
                primary: KeyCode.Tab,
                weight: 200,
                kbExpr: ( (ContextKeyExpr.and(
                    InlineCompletionContextKeys.inlineSuggestionVisible,
                     (EditorContextKeys.tabMovesFocus.toNegated()),
                    InlineCompletionContextKeys.inlineSuggestionHasIndentationLessThanTabSize,
                     (Context.Visible.toNegated()),
                     (EditorContextKeys.hoverFocused.toNegated())
                ))),
            }
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        if (controller) {
            controller.model.get()?.accept(controller.editor);
            controller.editor.focus();
        }
    }
}
class HideInlineCompletion extends EditorAction {
    static { this.ID = 'editor.action.inlineSuggest.hide'; }
    constructor() {
        super({
            id: HideInlineCompletion.ID,
            label: ( localizeWithPath(_moduleId, 9, "Hide Inline Suggestion")),
            alias: 'Hide Inline Suggestion',
            precondition: InlineCompletionContextKeys.inlineSuggestionVisible,
            kbOpts: {
                weight: 100,
                primary: KeyCode.Escape,
            }
        });
    }
    async run(accessor, editor) {
        const controller = InlineCompletionsController.get(editor);
        transaction(tx => {
            controller?.model.get()?.stop(tx);
        });
    }
}
class ToggleAlwaysShowInlineSuggestionToolbar extends Action2 {
    static { this.ID = 'editor.action.inlineSuggest.toggleAlwaysShowToolbar'; }
    constructor() {
        super({
            id: ToggleAlwaysShowInlineSuggestionToolbar.ID,
            title: ( localizeWithPath(_moduleId, 10, "Always Show Toolbar")),
            f1: false,
            precondition: undefined,
            menu: [{
                    id: MenuId.InlineSuggestionToolbar,
                    group: 'secondary',
                    order: 10,
                }],
            toggled: ( (ContextKeyExpr.equals('config.editor.inlineSuggest.showToolbar', 'always')))
        });
    }
    async run(accessor, editor) {
        const configService = accessor.get(IConfigurationService);
        const currentValue = configService.getValue('editor.inlineSuggest.showToolbar');
        const newValue = currentValue === 'always' ? 'onHover' : 'always';
        configService.updateValue('editor.inlineSuggest.showToolbar', newValue);
    }
}
export { AcceptInlineCompletion, AcceptNextLineOfInlineCompletion, AcceptNextWordOfInlineCompletion, HideInlineCompletion, ShowNextInlineSuggestionAction, ShowPreviousInlineSuggestionAction, ToggleAlwaysShowInlineSuggestionToolbar, TriggerInlineSuggestionAction };
