import { Codicon } from '../../../../base/common/codicons.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 { accessibilityHelpIsShown, accessibleViewIsShown, accessibleViewSupportsNavigation, accessibleViewGoToSymbolSupported, accessibleViewVerbosityEnabled, accessibleViewCurrentProviderId } from './accessibilityConfiguration.js';
import { IAccessibleViewService } from './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: "editor.action.accessibleViewNext" ,
            precondition: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
            keybinding: {
                primary: 512  | 94 ,
                weight: 200
            },
            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 AccessibleViewPreviousAction extends Action2 {
    constructor() {
        super({
            id: "editor.action.accessibleViewPrevious" ,
            precondition: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
            keybinding: {
                primary: 512  | 92 ,
                weight: 200
            },
            icon: Codicon.arrowUp,
            menu: [
                commandPalette,
                {
                    ...accessibleViewMenu,
                    when: ( (ContextKeyExpr.and(accessibleViewIsShown, accessibleViewSupportsNavigation))),
                }
            ],
            title: ( localizeWithPath(_moduleId, 1, "Show Previous in Accessible View"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).previous();
    }
}
registerAction2(AccessibleViewPreviousAction);
class AccessibleViewGoToSymbolAction extends Action2 {
    constructor() {
        super({
            id: "editor.action.accessibleViewGoToSymbol" ,
            precondition: ( (ContextKeyExpr.and(
                 (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                accessibleViewGoToSymbolSupported
            ))),
            keybinding: {
                primary: 2048  | 1024  | 45 ,
                secondary: [2048  | 1024  | 89 ],
                weight: 200  + 10
            },
            icon: Codicon.symbolField,
            menu: [
                commandPalette,
                {
                    ...accessibleViewMenu,
                    when: ( (ContextKeyExpr.and(
                         (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                        accessibleViewGoToSymbolSupported
                    ))),
                }
            ],
            title: ( localizeWithPath(_moduleId, 2, "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: "editor.action.accessibilityHelp" ,
    precondition: undefined,
    kbOpts: {
        primary: 512  | 59 ,
        weight: 200 ,
        linux: {
            primary: 512  | 1024  | 59 ,
            secondary: [512  | 59 ]
        },
        kbExpr: ( (accessibilityHelpIsShown.toNegated()))
    },
    menuOpts: [{
            menuId: MenuId.CommandPalette,
            group: '',
            title: ( localizeWithPath(_moduleId, 3, "Open Accessibility Help")),
            order: 1
        }],
}))));
const AccessibleViewAction = registerCommand(( (new MultiCommand({
    id: "editor.action.accessibleView" ,
    precondition: undefined,
    kbOpts: {
        primary: 512  | 60 ,
        weight: 200 ,
        linux: {
            primary: 512  | 1024  | 60 ,
            secondary: [512  | 60 ]
        }
    },
    menuOpts: [{
            menuId: MenuId.CommandPalette,
            group: '',
            title: ( localizeWithPath(_moduleId, 4, "Open Accessible View")),
            order: 1
        }],
}))));
class AccessibleViewDisableHintAction extends Action2 {
    constructor() {
        super({
            id: "editor.action.accessibleViewDisableHint" ,
            precondition: ( (ContextKeyExpr.and(
                 (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                accessibleViewVerbosityEnabled
            ))),
            keybinding: {
                primary: 512  | 64 ,
                weight: 200
            },
            icon: Codicon.bellSlash,
            menu: [
                commandPalette,
                {
                    id: MenuId.AccessibleView,
                    group: 'navigation',
                    when: ( (ContextKeyExpr.and(
                         (ContextKeyExpr.or(accessibleViewIsShown, accessibilityHelpIsShown)),
                        accessibleViewVerbosityEnabled
                    ))),
                }
            ],
            title: ( localizeWithPath(_moduleId, 5, "Disable Accessible View Hint"))
        });
    }
    run(accessor) {
        accessor.get(IAccessibleViewService).disableHint();
    }
}
registerAction2(AccessibleViewDisableHintAction);
class AccessibleViewAcceptInlineCompletionAction extends Action2 {
    constructor() {
        super({
            id: "editor.action.accessibleViewAcceptInlineCompletion" ,
            precondition: ( (ContextKeyExpr.and(accessibleViewIsShown,  (ContextKeyExpr.equals(
                accessibleViewCurrentProviderId.key,
                "inlineCompletions"
            ))))),
            keybinding: {
                primary: 2048  | 90 ,
                mac: { primary: 256  | 90  },
                weight: 200
            },
            icon: Codicon.check,
            menu: [
                commandPalette,
                {
                    id: MenuId.AccessibleView,
                    group: 'navigation',
                    order: 0,
                    when: ( (ContextKeyExpr.and(accessibleViewIsShown,  (ContextKeyExpr.equals(
                        accessibleViewCurrentProviderId.key,
                        "inlineCompletions"
                    )))))
                }
            ],
            title: ( localizeWithPath(_moduleId, 6, "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 };
