
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 { localize } from '../../../../nls.js';
import { MenuId, Action2, registerAction2 } 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 { accessibleViewIsShown, accessibleViewSupportsNavigation, accessibleViewContainsCodeBlocks, accessibleViewCurrentProviderId, accessibilityHelpIsShown, accessibleViewGoToSymbolSupported, accessibleViewVerbosityEnabled, accessibleViewHasUnassignedKeybindings, accessibleViewHasAssignedKeybindings } 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.service.js';
import { InlineCompletionsController } from '../../../../editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.js';

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: ( localize(4209, "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.or(( ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.PanelChat)), ( ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.InlineChat)), ( ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.QuickChat)))))),
            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: ( localize(4210, "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.or(( ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.PanelChat)), ( ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.InlineChat)), ( ContextKeyExpr.equals(accessibleViewCurrentProviderId.key, AccessibleViewProviderId.QuickChat)))))),
            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: ( localize(4211, "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: ( localize(4212, "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.symbolMisc,
            menu: [
                commandPalette,
                {
                    ...accessibleViewMenu,
                    when: ( ContextKeyExpr.and(( ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)), accessibleViewGoToSymbolSupported)),
                }
            ],
            title: ( localize(4213, "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: ( localize(4214, "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: ( localize(4215, "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: ( localize(4216, "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, accessibleViewHasUnassignedKeybindings)),
            icon: Codicon.recordKeys,
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.KeyK,
                weight: KeybindingWeight.WorkbenchContrib
            },
            menu: [
                {
                    id: MenuId.AccessibleView,
                    group: 'navigation',
                    order: 3,
                    when: accessibleViewHasUnassignedKeybindings,
                }
            ],
            title: ( localize(4217, "Accessibility Help Configure Unassigned Keybindings"))
        });
    }
    async run(accessor) {
        await accessor.get(IAccessibleViewService).configureKeybindings(true);
    }
}
registerAction2(AccessibilityHelpConfigureKeybindingsAction);
class AccessibilityHelpConfigureAssignedKeybindingsAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.AccessibilityHelpConfigureAssignedKeybindings,
            precondition: ( ContextKeyExpr.and(accessibilityHelpIsShown, accessibleViewHasAssignedKeybindings)),
            icon: Codicon.recordKeys,
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.KeyA,
                weight: KeybindingWeight.WorkbenchContrib
            },
            menu: [
                {
                    id: MenuId.AccessibleView,
                    group: 'navigation',
                    order: 4,
                    when: accessibleViewHasAssignedKeybindings,
                }
            ],
            title: ( localize(4218, "Accessibility Help Configure Assigned Keybindings"))
        });
    }
    async run(accessor) {
        await accessor.get(IAccessibleViewService).configureKeybindings(false);
    }
}
registerAction2(AccessibilityHelpConfigureAssignedKeybindingsAction);
class AccessibilityHelpOpenHelpLinkAction extends Action2 {
    constructor() {
        super({
            id: AccessibilityCommandId.AccessibilityHelpOpenHelpLink,
            precondition: ( ContextKeyExpr.and(accessibilityHelpIsShown)),
            keybinding: {
                primary: KeyMod$1.Alt | KeyCode.KeyH,
                weight: KeybindingWeight.WorkbenchContrib
            },
            title: ( localize(4219, "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: ( localize(4220, "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 };
