import { Codicon } from '../../../../base/common/codicons.js';
import { KeyMod as KeyMod$1, KeyCode } from '../../../../base/common/keyCodes.js';
import { MultiCommand } from '../../../../editor/browser/editorExtensions.js';
import { localizeWithPath } from '../../../../nls.js';
import { registerAction2, MenuId, Action2 } from '../../../../platform/actions/common/actions.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { KeybindingWeight } from '../../../../platform/keybinding/common/keybindingsRegistry.js';
import { AccessibilityCommandId } from '../common/accessibilityCommands.js';
import { accessibilityHelpIsShown, accessibleViewIsShown, accessibleViewSupportsNavigation, accessibleViewContainsCodeBlocks, accessibleViewCurrentProviderId, accessibleViewGoToSymbolSupported, accessibleViewVerbosityEnabled } from './accessibilityConfiguration.js';
import { AccessibleViewProviderId } from '../../../../platform/accessibility/browser/accessibleView.js';
import { IAccessibleViewService } from '../../../../platform/accessibility/browser/accessibleView.service.js';
import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js';
import { InlineCompletionsController } from '../../../../editor/contrib/inlineCompletions/browser/inlineCompletionsController.js';
const _moduleId = "vs/workbench/contrib/accessibility/browser/accessibleViewActions";
const accessibleViewMenu = {
    id: MenuId.AccessibleView,
    group: 'navigation',
    when: accessibleViewIsShown
};
const commandPalette = {
    id: MenuId.CommandPalette,
    group: '',
    order: 1
};
class AccessibleViewNextAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.ShowNext,
            precondition: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.BracketRight,
                weight: KeybindingWeight.WorkbenchContrib
            },
            menu: [
                commandPalette,
                {
                    ...accessibleViewMenu,
                    when: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
                }
            ],
            icon: Codicon.arrowDown,
            title: ( localizeWithPath(_moduleId, 0, "Show Next in Accessible View"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).next();
    }
}
registerAction2(AccessibleViewNextAction);
class AccessibleViewNextCodeBlockAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.NextCodeBlock,
            precondition: ( (ContextKeyExpr.and(
                accessibleViewContainsCodeBlocks,
                 (ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.Chat))
            ))),
            keybinding: {
                primary: KeyMod$1.CtrlCmd | KeyMod$1.Alt | KeyCode.PageDown,
                mac: { primary: KeyMod$1.CtrlCmd | KeyMod$1.Alt | KeyCode.PageDown, },
                weight: KeybindingWeight.WorkbenchContrib,
            },
            icon: Codicon.arrowRight,
            menu: {
                ...accessibleViewMenu,
                when: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewContainsCodeBlocks))),
            },
            title: ( localizeWithPath(_moduleId, 1, "Accessible View: Next Code Block"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).navigateToCodeBlock('next');
    }
}
registerAction2(AccessibleViewNextCodeBlockAction);
class AccessibleViewPreviousCodeBlockAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.PreviousCodeBlock,
            precondition: ( (ContextKeyExpr.and(
                accessibleViewContainsCodeBlocks,
                 (ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.Chat))
            ))),
            keybinding: {
                primary: KeyMod$1.CtrlCmd | KeyMod$1.Alt | KeyCode.PageUp,
                mac: { primary: KeyMod$1.CtrlCmd | KeyMod$1.Alt | KeyCode.PageUp, },
                weight: KeybindingWeight.WorkbenchContrib,
            },
            icon: Codicon.arrowLeft,
            menu: {
                ...accessibleViewMenu,
                when: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewContainsCodeBlocks))),
            },
            title: ( localizeWithPath(_moduleId, 2, "Accessible View: Previous Code Block"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).navigateToCodeBlock('previous');
    }
}
registerAction2(AccessibleViewPreviousCodeBlockAction);
class AccessibleViewPreviousAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.ShowPrevious,
            precondition: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.BracketLeft,
                weight: KeybindingWeight.WorkbenchContrib
            },
            icon: Codicon.arrowUp,
            menu: [
                commandPalette,
                {
                    ...accessibleViewMenu,
                    when: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
                }
            ],
            title: ( localizeWithPath(_moduleId, 3, "Show Previous in Accessible View"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).previous();
    }
}
registerAction2(AccessibleViewPreviousAction);
class AccessibleViewGoToSymbolAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.GoToSymbol,
            precondition: ( (ContextKeyExpr.and(
                 (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                accessibleViewGoToSymbolSupported
            ))),
            keybinding: {
                primary: KeyMod$1.CtrlCmd | KeyMod$1.Shift | KeyCode.KeyO,
                secondary: [KeyMod$1.CtrlCmd | KeyMod$1.Shift | KeyCode.Period],
                weight: KeybindingWeight.WorkbenchContrib + 10
            },
            icon: Codicon.symbolField,
            menu: [
                commandPalette,
                {
                    ...accessibleViewMenu,
                    when: ( (ContextKeyExpr.and(
                         (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                        accessibleViewGoToSymbolSupported
                    ))),
                }
            ],
            title: ( localizeWithPath(_moduleId, 4, "Go To Symbol in Accessible View"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).goToSymbol();
    }
}
registerAction2(AccessibleViewGoToSymbolAction);
function registerCommand(command) {
    command.register();
    return command;
}
const AccessibilityHelpAction = registerCommand(( (new MultiCommand({
    id: AccessibilityCommandId.OpenAccessibilityHelp,
    precondition: undefined,
    kbOpts: {
        primary: KeyMod$1.Alt | KeyCode.F1,
        weight: KeybindingWeight.WorkbenchContrib,
        linux: {
            primary: KeyMod$1.Alt | KeyMod$1.Shift | KeyCode.F1,
            secondary: [KeyMod$1.Alt | KeyCode.F1]
        },
        kbExpr: ( (accessibilityHelpIsShown.toNegated()))
    },
    menuOpts: [{
            menuId: MenuId.CommandPalette,
            group: '',
            title: ( localizeWithPath(_moduleId, 5, "Open Accessibility Help")),
            order: 1
        }],
}))));
const AccessibleViewAction = registerCommand(( (new MultiCommand({
    id: AccessibilityCommandId.OpenAccessibleView,
    precondition: undefined,
    kbOpts: {
        primary: KeyMod$1.Alt | KeyCode.F2,
        weight: KeybindingWeight.WorkbenchContrib,
        linux: {
            primary: KeyMod$1.Alt | KeyMod$1.Shift | KeyCode.F2,
            secondary: [KeyMod$1.Alt | KeyCode.F2]
        }
    },
    menuOpts: [{
            menuId: MenuId.CommandPalette,
            group: '',
            title: ( localizeWithPath(_moduleId, 6, "Open Accessible View")),
            order: 1
        }],
}))));
class AccessibleViewDisableHintAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.DisableVerbosityHint,
            precondition: ( (ContextKeyExpr.and(
                 (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                accessibleViewVerbosityEnabled
            ))),
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.F6,
                weight: KeybindingWeight.WorkbenchContrib
            },
            icon: Codicon.bellSlash,
            menu: [
                commandPalette,
                {
                    id: MenuId.AccessibleView,
                    group: 'navigation',
                    when: ( (ContextKeyExpr.and(
                         (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                        accessibleViewVerbosityEnabled
                    ))),
                }
            ],
            title: ( localizeWithPath(_moduleId, 7, "Disable Accessible View Hint"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).disableHint();
    }
}
registerAction2(AccessibleViewDisableHintAction);
class AccessibilityHelpConfigureKeybindingsAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.AccessibilityHelpConfigureKeybindings,
            precondition: ( (ContextKeyExpr.and(accessibilityHelpIsShown))),
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.KeyK,
                weight: KeybindingWeight.WorkbenchContrib
            },
            title: ( localizeWithPath(_moduleId, 8, "Accessibility Help Configure Keybindings"))
        });
    }
    async run(accessor) {
        await accessor.get(IAccessibleViewService).configureKeybindings();
    }
}
registerAction2(AccessibilityHelpConfigureKeybindingsAction);
class AccessibilityHelpOpenHelpLinkAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.AccessibilityHelpOpenHelpLink,
            precondition: ( (ContextKeyExpr.and(accessibilityHelpIsShown))),
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.KeyH,
                weight: KeybindingWeight.WorkbenchContrib
            },
            title: ( localizeWithPath(_moduleId, 9, "Accessibility Help Open Help Link"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).openHelpLink();
    }
}
registerAction2(AccessibilityHelpOpenHelpLinkAction);
class AccessibleViewAcceptInlineCompletionAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.AccessibleViewAcceptInlineCompletion,
            precondition: ( (ContextKeyExpr.and(accessibleViewIsShown,  (ContextKeyExpr.equals(
                accessibleViewCurrentProviderId.key,
                AccessibleViewProviderId.InlineCompletions
            ))))),
            keybinding: {
                primary: KeyMod$1.CtrlCmd | KeyCode.Slash,
                mac: { primary: KeyMod$1.WinCtrl | KeyCode.Slash },
                weight: KeybindingWeight.WorkbenchContrib
            },
            icon: Codicon.check,
            menu: [
                commandPalette,
                {
                    id: MenuId.AccessibleView,
                    group: 'navigation',
                    order: 0,
                    when: ( (ContextKeyExpr.and(accessibleViewIsShown,  (ContextKeyExpr.equals(
                        accessibleViewCurrentProviderId.key,
                        AccessibleViewProviderId.InlineCompletions
                    )))))
                }
            ],
            title: ( localizeWithPath(_moduleId, 10, "Accept Inline Completion"))
        });
    }
    async run(accessor) {
        const codeEditorService = accessor.get(ICodeEditorService);
        const editor = codeEditorService.getActiveCodeEditor() || codeEditorService.getFocusedCodeEditor();
        if (!editor) {
            return;
        }
        const model = InlineCompletionsController.get(editor)?.model.get();
        const state = model?.state.get();
        if (!model || !state) {
            return;
        }
        await model.accept(editor);
        model.stop();
        editor.focus();
    }
}
registerAction2(AccessibleViewAcceptInlineCompletionAction);
export { AccessibilityHelpAction, AccessibleViewAction };
