import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { addDisposableListener, EventType, isActiveElement, getActiveWindow } from '../../../../base/browser/dom.js';
import { StandardKeyboardEvent } from '../../../../base/browser/keyboardEvent.js';
import { alert } from '../../../../base/browser/ui/aria/aria.js';
import { Codicon } from '../../../../base/common/codicons.js';
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
import marked from 'vscode-marked';
import { isMacintosh } from '../../../../base/common/platform.js';
import { ThemeIcon } from '../../../../base/common/themables.js';
import { URI } from '../../../../base/common/uri.js';
import { EditorExtensionsRegistry } from '../../../../editor/browser/editorExtensions.js';
import { CodeEditorWidget } from '../../../../editor/browser/widget/codeEditorWidget.js';
import { Position } from '../../../../editor/common/core/position.js';
import { IModelService } from '../../../../editor/common/services/model.js';
import { AccessibilityHelpNLS } from '../../../../editor/common/standaloneStrings.js';
import { CodeActionController } from '../../../../editor/contrib/codeAction/browser/codeActionController.js';
import { localizeWithPath } from '../../../../nls.js';
import { IAccessibilityService } from '../../../../platform/accessibility/common/accessibility.js';
import { createAndFillInActionBarActions } from '../../../../platform/actions/browser/menuEntryActionViewItem.js';
import { WorkbenchToolBar } from '../../../../platform/actions/browser/toolbar.js';
import { MenuId, IMenuService } from '../../../../platform/actions/common/actions.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
import { IContextViewService } from '../../../../platform/contextview/browser/contextView.js';
import { createDecorator, IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { IKeybindingService } from '../../../../platform/keybinding/common/keybinding.js';
import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';
import { IOpenerService } from '../../../../platform/opener/common/opener.js';
import { IQuickInputService } from '../../../../platform/quickinput/common/quickInput.js';
import { accessibilityHelpIsShown, accessibleViewIsShown, accessibleViewSupportsNavigation, accessibleViewVerbosityEnabled, accessibleViewGoToSymbolSupported, accessibleViewCurrentProviderId, accessibleViewOnLastLine } from './accessibilityConfiguration.js';
import { getSimpleEditorOptions } from '../../codeEditor/browser/simpleEditorOptions.js';
const IAccessibleViewService = ( createDecorator('accessibleViewService'));
let AccessibleView = class AccessibleView extends Disposable {
    get editorWidget() { return this._editorWidget; }
    constructor(_openerService, _instantiationService, _configurationService, _modelService, _contextViewService, _contextKeyService, _accessibilityService, _keybindingService, _layoutService, _menuService) {
        super();
        this._openerService = _openerService;
        this._instantiationService = _instantiationService;
        this._configurationService = _configurationService;
        this._modelService = _modelService;
        this._contextViewService = _contextViewService;
        this._contextKeyService = _contextKeyService;
        this._accessibilityService = _accessibilityService;
        this._keybindingService = _keybindingService;
        this._layoutService = _layoutService;
        this._menuService = _menuService;
        this._accessiblityHelpIsShown = accessibilityHelpIsShown.bindTo(this._contextKeyService);
        this._accessibleViewIsShown = accessibleViewIsShown.bindTo(this._contextKeyService);
        this._accessibleViewSupportsNavigation = accessibleViewSupportsNavigation.bindTo(this._contextKeyService);
        this._accessibleViewVerbosityEnabled = accessibleViewVerbosityEnabled.bindTo(this._contextKeyService);
        this._accessibleViewGoToSymbolSupported = accessibleViewGoToSymbolSupported.bindTo(this._contextKeyService);
        this._accessibleViewCurrentProviderId = accessibleViewCurrentProviderId.bindTo(this._contextKeyService);
        this._onLastLine = accessibleViewOnLastLine.bindTo(this._contextKeyService);
        this._container = document.createElement('div');
        this._container.classList.add('accessible-view');
        if (this._configurationService.getValue("accessibility.hideAccessibleView" )) {
            this._container.classList.add('hide');
        }
        const codeEditorWidgetOptions = {
            contributions: EditorExtensionsRegistry.getEditorContributions().filter(c => c.id !== CodeActionController.ID)
        };
        const titleBar = document.createElement('div');
        titleBar.classList.add('accessible-view-title-bar');
        this._title = document.createElement('div');
        this._title.classList.add('accessible-view-title');
        titleBar.appendChild(this._title);
        const actionBar = document.createElement('div');
        actionBar.classList.add('accessible-view-action-bar');
        titleBar.appendChild(actionBar);
        this._container.appendChild(titleBar);
        this._toolbar = this._register(_instantiationService.createInstance(WorkbenchToolBar, actionBar, { orientation: 0  }));
        this._toolbar.context = { viewId: 'accessibleView' };
        const toolbarElt = this._toolbar.getElement();
        toolbarElt.tabIndex = 0;
        const editorOptions = {
            ...getSimpleEditorOptions(this._configurationService),
            lineDecorationsWidth: 6,
            dragAndDrop: false,
            cursorWidth: 1,
            wrappingStrategy: 'advanced',
            wrappingIndent: 'none',
            padding: { top: 2, bottom: 2 },
            quickSuggestions: false,
            renderWhitespace: 'none',
            dropIntoEditor: { enabled: false },
            readOnly: true,
            fontFamily: 'var(--monaco-monospace-font)'
        };
        this._editorWidget = this._register(this._instantiationService.createInstance(CodeEditorWidget, this._container, editorOptions, codeEditorWidgetOptions));
        this._register(this._accessibilityService.onDidChangeScreenReaderOptimized(() => {
            if (this._currentProvider && this._accessiblityHelpIsShown.get()) {
                this.show(this._currentProvider);
            }
        }));
        this._register(this._configurationService.onDidChangeConfiguration(e => {
            if (this._currentProvider && e.affectsConfiguration(this._currentProvider.verbositySettingKey)) {
                if (this._accessiblityHelpIsShown.get()) {
                    this.show(this._currentProvider);
                }
                this._accessibleViewVerbosityEnabled.set(this._configurationService.getValue(this._currentProvider.verbositySettingKey));
                this._updateToolbar(this._currentProvider.actions, this._currentProvider.options.type);
            }
            if (e.affectsConfiguration("accessibility.hideAccessibleView" )) {
                this._container.classList.toggle('hide', this._configurationService.getValue("accessibility.hideAccessibleView" ));
            }
        }));
        this._register(this._editorWidget.onDidDispose(() => this._resetContextKeys()));
        this._register(this._editorWidget.onDidChangeCursorPosition(() => {
            this._onLastLine.set(this._editorWidget.getPosition()?.lineNumber === this._editorWidget.getModel()?.getLineCount());
        }));
    }
    _resetContextKeys() {
        this._accessiblityHelpIsShown.reset();
        this._accessibleViewIsShown.reset();
        this._accessibleViewSupportsNavigation.reset();
        this._accessibleViewVerbosityEnabled.reset();
        this._accessibleViewGoToSymbolSupported.reset();
        this._accessibleViewCurrentProviderId.reset();
    }
    getPosition(id) {
        if (!id || !this._lastProvider || this._lastProvider.id !== id) {
            return undefined;
        }
        return this._editorWidget.getPosition() || undefined;
    }
    setPosition(position, reveal) {
        this._editorWidget.setPosition(position);
        if (reveal) {
            this._editorWidget.revealPosition(position);
        }
    }
    showLastProvider(id) {
        if (!this._lastProvider || this._lastProvider.options.id !== id) {
            return;
        }
        this.show(this._lastProvider);
    }
    show(provider, symbol, showAccessibleViewHelp, position) {
        provider = provider ?? this._currentProvider;
        if (!provider) {
            return;
        }
        const delegate = {
            getAnchor: () => { return { x: (getActiveWindow().innerWidth / 2) - ((Math.min(this._layoutService.activeContainerDimension.width * 0.62 , 600 )) / 2), y: this._layoutService.activeContainerOffset.quickPickTop }; },
            render: (container) => {
                container.classList.add('accessible-view-container');
                return this._render(provider, container, showAccessibleViewHelp);
            },
            onHide: () => {
                if (!showAccessibleViewHelp) {
                    this._updateLastProvider();
                    this._currentProvider = undefined;
                    this._resetContextKeys();
                }
            }
        };
        this._contextViewService.showContextView(delegate);
        if (position) {
            setTimeout(() => {
                this._editorWidget.revealLine(position.lineNumber);
                this._editorWidget.setSelection({ startLineNumber: position.lineNumber, startColumn: position.column, endLineNumber: position.lineNumber, endColumn: position.column });
            }, 10);
        }
        if (symbol && this._currentProvider) {
            this.showSymbol(this._currentProvider, symbol);
        }
        if (provider.onDidRequestClearLastProvider) {
            this._register(provider.onDidRequestClearLastProvider((id) => {
                if (this._lastProvider?.options.id === id) {
                    this._lastProvider = undefined;
                }
            }));
        }
        if (provider.options.id) {
            this._lastProvider = provider;
        }
    }
    previous() {
        if (!this._currentProvider) {
            return;
        }
        this._currentProvider.previous?.();
    }
    next() {
        if (!this._currentProvider) {
            return;
        }
        this._currentProvider.next?.();
    }
    goToSymbol() {
        if (!this._currentProvider) {
            return;
        }
        this._instantiationService.createInstance(AccessibleViewSymbolQuickPick, this).show(this._currentProvider);
    }
    getSymbols() {
        if (!this._currentProvider || !this._currentContent) {
            return;
        }
        const symbols = this._currentProvider.getSymbols?.() || [];
        if (symbols?.length) {
            return symbols;
        }
        if (this._currentProvider.options.language && this._currentProvider.options.language !== 'markdown') {
            return;
        }
        const markdownTokens = marked.lexer(this._currentContent);
        if (!markdownTokens) {
            return;
        }
        this._convertTokensToSymbols(markdownTokens, symbols);
        return symbols.length ? symbols : undefined;
    }
    _convertTokensToSymbols(tokens, symbols) {
        let firstListItem;
        for (const token of tokens) {
            let label = undefined;
            if ('type' in token) {
                switch (token.type) {
                    case 'heading':
                    case 'paragraph':
                    case 'code':
                        label = token.text;
                        break;
                    case 'list': {
                        const firstItem = token.items?.[0];
                        if (!firstItem) {
                            break;
                        }
                        firstListItem = `- ${firstItem.text}`;
                        label = token.items?.map(i => i.text).join(', ');
                        break;
                    }
                }
            }
            if (label) {
                symbols.push({ markdownToParse: label, label: ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'symbolLabel',
                    "({0}) {1}",
                    token.type,
                    label
                )), ariaLabel: ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'symbolLabelAria',
                    "({0}) {1}",
                    token.type,
                    label
                )), firstListItem });
                firstListItem = undefined;
            }
        }
    }
    showSymbol(provider, symbol) {
        if (!this._currentContent) {
            return;
        }
        let lineNumber = symbol.lineNumber;
        const markdownToParse = symbol.markdownToParse;
        if (lineNumber === undefined && markdownToParse === undefined) {
            return;
        }
        if (lineNumber === undefined && markdownToParse) {
            const index = this._currentContent.split('\n').findIndex(line => line.includes(markdownToParse.split('\n')[0]) || (symbol.firstListItem && line.includes(symbol.firstListItem))) ?? -1;
            if (index >= 0) {
                lineNumber = index + 1;
            }
        }
        if (lineNumber === undefined) {
            return;
        }
        this.show(provider, undefined, undefined, { lineNumber, column: 1 });
        this._updateContextKeys(provider, true);
    }
    disableHint() {
        if (!this._currentProvider) {
            return;
        }
        this._configurationService.updateValue(this._currentProvider?.verbositySettingKey, false);
        alert(( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'disableAccessibilityHelp',
            '{0} accessibility verbosity is now disabled',
            this._currentProvider.verbositySettingKey
        )));
    }
    _updateContextKeys(provider, shown) {
        if (provider.options.type === "help" ) {
            this._accessiblityHelpIsShown.set(shown);
            this._accessibleViewIsShown.reset();
        }
        else {
            this._accessibleViewIsShown.set(shown);
            this._accessiblityHelpIsShown.reset();
        }
        if (provider.next && provider.previous) {
            this._accessibleViewSupportsNavigation.set(true);
        }
        else {
            this._accessibleViewSupportsNavigation.reset();
        }
        const verbosityEnabled = this._configurationService.getValue(provider.verbositySettingKey);
        this._accessibleViewVerbosityEnabled.set(verbosityEnabled);
        this._accessibleViewGoToSymbolSupported.set(this._goToSymbolsSupported() ? this.getSymbols()?.length > 0 : false);
    }
    _render(provider, container, showAccessibleViewHelp) {
        if (!showAccessibleViewHelp) {
            this._currentProvider = provider;
            this._accessibleViewCurrentProviderId.set(provider.id);
        }
        const value = this._configurationService.getValue(provider.verbositySettingKey);
        const readMoreLink = provider.options.readMoreUrl ? ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            "openDoc",
            "\n\nOpen a browser window with more information related to accessibility (H)."
        )) : '';
        let disableHelpHint = '';
        if (provider.options.type === "help"  && !!value) {
            disableHelpHint = this._getDisableVerbosityHint(provider.verbositySettingKey);
        }
        const accessibilitySupport = this._accessibilityService.isScreenReaderOptimized();
        let message = '';
        if (provider.options.type === "help" ) {
            const turnOnMessage = (isMacintosh
                ? AccessibilityHelpNLS.changeConfigToOnMac
                : AccessibilityHelpNLS.changeConfigToOnWinLinux);
            if (accessibilitySupport && provider.verbositySettingKey === "accessibility.verbosity.editor" ) {
                message = AccessibilityHelpNLS.auto_on;
                message += '\n';
            }
            else if (!accessibilitySupport) {
                message = AccessibilityHelpNLS.auto_off + '\n' + turnOnMessage;
                message += '\n';
            }
        }
        const verbose = this._configurationService.getValue(provider.verbositySettingKey);
        const exitThisDialogHint = verbose && !provider.options.position ? ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'exit',
            '\n\nExit this dialog (Escape).'
        )) : '';
        this._currentContent = message + provider.provideContent() + readMoreLink + disableHelpHint + exitThisDialogHint;
        this._updateContextKeys(provider, true);
        this._getTextModel(( URI.from(
            { path: `accessible-view-${provider.verbositySettingKey}`, scheme: 'accessible-view', fragment: this._currentContent }
        ))).then((model) => {
            if (!model) {
                return;
            }
            this._editorWidget.setModel(model);
            const domNode = this._editorWidget.getDomNode();
            if (!domNode) {
                return;
            }
            model.setLanguage(provider.options.language ?? 'markdown');
            container.appendChild(this._container);
            let actionsHint = '';
            const verbose = this._configurationService.getValue(provider.verbositySettingKey);
            const hasActions = this._accessibleViewSupportsNavigation.get() || this._accessibleViewVerbosityEnabled.get() || this._accessibleViewGoToSymbolSupported.get() || this._currentProvider?.actions;
            if (verbose && !showAccessibleViewHelp && hasActions) {
                actionsHint = provider.options.position ? ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'ariaAccessibleViewActionsBottom',
                    'Explore actions such as disabling this hint (Shift+Tab), use Escape to exit this dialog.'
                )) : ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'ariaAccessibleViewActions',
                    'Explore actions such as disabling this hint (Shift+Tab).'
                ));
            }
            let ariaLabel = provider.options.type === "help"  ? ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'accessibility-help',
                "Accessibility Help"
            )) : ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'accessible-view',
                "Accessible View"
            ));
            this._title.textContent = ariaLabel;
            if (actionsHint && provider.options.type === "view" ) {
                ariaLabel = ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'accessible-view-hint',
                    "Accessible View, {0}",
                    actionsHint
                ));
            }
            else if (actionsHint) {
                ariaLabel = ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'accessibility-help-hint',
                    "Accessibility Help, {0}",
                    actionsHint
                ));
            }
            this._editorWidget.updateOptions({ ariaLabel });
            this._editorWidget.focus();
            if (this._currentProvider?.options.position) {
                const position = this._editorWidget.getPosition();
                const isDefaultPosition = position?.lineNumber === 1 && position.column === 1;
                if (this._currentProvider.options.position === 'bottom' || this._currentProvider.options.position === 'initial-bottom' && isDefaultPosition) {
                    const lastLine = this.editorWidget.getModel()?.getLineCount();
                    const position = lastLine !== undefined && lastLine > 0 ? ( new Position(lastLine, 1)) : undefined;
                    if (position) {
                        this._editorWidget.setPosition(position);
                        this._editorWidget.revealLine(position.lineNumber);
                    }
                }
            }
        });
        this._updateToolbar(provider.actions, provider.options.type);
        const hide = (e) => {
            provider.onClose();
            e.stopPropagation();
            this._contextViewService.hideContextView();
            this._updateContextKeys(provider, false);
            this._lastProvider = undefined;
        };
        const disposableStore = ( new DisposableStore());
        disposableStore.add(this._editorWidget.onKeyDown((e) => {
            if (e.keyCode === 9  || shouldHide(e.browserEvent, this._keybindingService, this._configurationService)) {
                hide(e);
            }
            else if (e.keyCode === 38  && provider.options.readMoreUrl) {
                const url = provider.options.readMoreUrl;
                alert(AccessibilityHelpNLS.openingDocs);
                this._openerService.open(( URI.parse(url)));
                e.preventDefault();
                e.stopPropagation();
            }
            provider.onKeyDown?.(e);
        }));
        disposableStore.add(addDisposableListener(this._toolbar.getElement(), EventType.KEY_DOWN, (e) => {
            const keyboardEvent = ( new StandardKeyboardEvent(e));
            if (keyboardEvent.equals(9 )) {
                hide(e);
            }
        }));
        disposableStore.add(this._editorWidget.onDidBlurEditorWidget(() => {
            if (!isActiveElement(this._toolbar.getElement())) {
                this._contextViewService.hideContextView();
            }
        }));
        disposableStore.add(this._editorWidget.onDidContentSizeChange(() => this._layout()));
        disposableStore.add(this._layoutService.onDidLayoutActiveContainer(() => this._layout()));
        return disposableStore;
    }
    _updateToolbar(providedActions, type) {
        this._toolbar.setAriaLabel(type === "help"  ? ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'accessibleHelpToolbar',
            'Accessibility Help'
        )) : ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'accessibleViewToolbar',
            "Accessible View"
        )));
        const menuActions = [];
        const toolbarMenu = this._register(this._menuService.createMenu(MenuId.AccessibleView, this._contextKeyService));
        createAndFillInActionBarActions(toolbarMenu, {}, menuActions);
        if (providedActions) {
            for (const providedAction of providedActions) {
                providedAction.class = providedAction.class || ThemeIcon.asClassName(Codicon.primitiveSquare);
                providedAction.checked = undefined;
            }
            this._toolbar.setActions([...providedActions, ...menuActions]);
        }
        else {
            this._toolbar.setActions(menuActions);
        }
    }
    _layout() {
        const dimension = this._layoutService.activeContainerDimension;
        const maxHeight = dimension.height && dimension.height * .4;
        const height = Math.min(maxHeight, this._editorWidget.getContentHeight());
        const width = Math.min(dimension.width * 0.62 , 600 );
        this._editorWidget.layout({ width, height });
    }
    async _getTextModel(resource) {
        const existing = this._modelService.getModel(resource);
        if (existing && !existing.isDisposed()) {
            return existing;
        }
        return this._modelService.createModel(resource.fragment, null, resource, false);
    }
    _goToSymbolsSupported() {
        if (!this._currentProvider) {
            return false;
        }
        return this._currentProvider.options.type === "help"  || this._currentProvider.options.language === 'markdown' || this._currentProvider.options.language === undefined || !!this._currentProvider.getSymbols?.();
    }
    _updateLastProvider() {
        if (!this._currentProvider) {
            return;
        }
        const lastProvider = Object.assign({}, this._currentProvider);
        lastProvider.provideContent = this._currentProvider.provideContent.bind(lastProvider);
        lastProvider.options = Object.assign({}, this._currentProvider.options);
        lastProvider.verbositySettingKey = this._currentProvider.verbositySettingKey;
        return lastProvider;
    }
    showAccessibleViewHelp() {
        const lastProvider = this._updateLastProvider();
        if (!lastProvider) {
            return;
        }
        const accessibleViewHelpProvider = {
            id: lastProvider.id,
            provideContent: () => lastProvider.options.customHelp ? lastProvider?.options.customHelp() : this._getAccessibleViewHelpDialogContent(this._goToSymbolsSupported()),
            onClose: () => this.show(lastProvider),
            options: { type: "help"  },
            verbositySettingKey: lastProvider.verbositySettingKey
        };
        this._contextViewService.hideContextView();
        setTimeout(() => this.show(accessibleViewHelpProvider, undefined, true), 100);
    }
    _getAccessibleViewHelpDialogContent(providerHasSymbols) {
        const navigationHint = this._getNavigationHint();
        const goToSymbolHint = this._getGoToSymbolHint(providerHasSymbols);
        const toolbarHint = ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'toolbar',
            "Navigate to the toolbar (Shift+Tab))."
        ));
        let hint = ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'intro',
            "In the accessible view, you can:\n"
        ));
        if (navigationHint) {
            hint += ' - ' + navigationHint + '\n';
        }
        if (goToSymbolHint) {
            hint += ' - ' + goToSymbolHint + '\n';
        }
        if (toolbarHint) {
            hint += ' - ' + toolbarHint + '\n';
        }
        return hint;
    }
    _getNavigationHint() {
        let hint = '';
        const nextKeybinding = this._keybindingService.lookupKeybinding("editor.action.accessibleViewNext" )?.getAriaLabel();
        const previousKeybinding = this._keybindingService.lookupKeybinding("editor.action.accessibleViewPrevious" )?.getAriaLabel();
        if (nextKeybinding && previousKeybinding) {
            hint = ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'accessibleViewNextPreviousHint',
                "Show the next ({0}) or previous ({1}) item.",
                nextKeybinding,
                previousKeybinding
            ));
        }
        else {
            hint = ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'chatAccessibleViewNextPreviousHintNoKb',
                "Show the next or previous item by configuring keybindings for the Show Next & Previous in Accessible View commands."
            ));
        }
        return hint;
    }
    _getDisableVerbosityHint(verbositySettingKey) {
        if (!this._configurationService.getValue(verbositySettingKey)) {
            return '';
        }
        let hint = '';
        const disableKeybinding = this._keybindingService.lookupKeybinding("editor.action.accessibleViewDisableHint" , this._contextKeyService)?.getAriaLabel();
        if (disableKeybinding) {
            hint = ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'acessibleViewDisableHint',
                "\n\nDisable accessibility verbosity for this feature ({0}).",
                disableKeybinding
            ));
        }
        else {
            hint = ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'accessibleViewDisableHintNoKb',
                "\n\nAdd a keybinding for the command Disable Accessible View Hint, which disables accessibility verbosity for this feature.s"
            ));
        }
        return hint;
    }
    _getGoToSymbolHint(providerHasSymbols) {
        const goToSymbolKb = this._keybindingService.lookupKeybinding("editor.action.accessibleViewGoToSymbol" )?.getAriaLabel();
        let goToSymbolHint = '';
        if (providerHasSymbols) {
            if (goToSymbolKb) {
                goToSymbolHint = ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'goToSymbolHint',
                    'Go to a symbol ({0})',
                    goToSymbolKb
                ));
            }
            else {
                goToSymbolHint = ( localizeWithPath(
                    'vs/workbench/contrib/accessibility/browser/accessibleView',
                    'goToSymbolHintNoKb',
                    'To go to a symbol, configure a keybinding for the command Go To Symbol in Accessible View'
                ));
            }
        }
        return goToSymbolHint;
    }
};
AccessibleView = ( __decorate([
    ( __param(0, IOpenerService)),
    ( __param(1, IInstantiationService)),
    ( __param(2, IConfigurationService)),
    ( __param(3, IModelService)),
    ( __param(4, IContextViewService)),
    ( __param(5, IContextKeyService)),
    ( __param(6, IAccessibilityService)),
    ( __param(7, IKeybindingService)),
    ( __param(8, ILayoutService)),
    ( __param(9, IMenuService))
], AccessibleView));
let AccessibleViewService = class AccessibleViewService extends Disposable {
    constructor(_instantiationService, _configurationService, _keybindingService) {
        super();
        this._instantiationService = _instantiationService;
        this._configurationService = _configurationService;
        this._keybindingService = _keybindingService;
    }
    show(provider, position) {
        if (!this._accessibleView) {
            this._accessibleView = this._register(this._instantiationService.createInstance(AccessibleView));
        }
        this._accessibleView.show(provider, undefined, undefined, position);
    }
    showLastProvider(id) {
        this._accessibleView?.showLastProvider(id);
    }
    next() {
        this._accessibleView?.next();
    }
    previous() {
        this._accessibleView?.previous();
    }
    goToSymbol() {
        this._accessibleView?.goToSymbol();
    }
    getOpenAriaHint(verbositySettingKey) {
        if (!this._configurationService.getValue(verbositySettingKey)) {
            return null;
        }
        const keybinding = this._keybindingService.lookupKeybinding("editor.action.accessibleView" )?.getAriaLabel();
        let hint = null;
        if (keybinding) {
            hint = ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'acessibleViewHint',
                "Inspect this in the accessible view with {0}",
                keybinding
            ));
        }
        else {
            hint = ( localizeWithPath(
                'vs/workbench/contrib/accessibility/browser/accessibleView',
                'acessibleViewHintNoKbEither',
                "Inspect this in the accessible view via the command Open Accessible View which is currently not triggerable via keybinding."
            ));
        }
        return hint;
    }
    disableHint() {
        this._accessibleView?.disableHint();
    }
    showAccessibleViewHelp() {
        this._accessibleView?.showAccessibleViewHelp();
    }
    getPosition(id) {
        return this._accessibleView?.getPosition(id) ?? undefined;
    }
    getLastPosition() {
        const lastLine = this._accessibleView?.editorWidget.getModel()?.getLineCount();
        return lastLine !== undefined && lastLine > 0 ? ( new Position(lastLine, 1)) : undefined;
    }
    setPosition(position, reveal) {
        const editorWidget = this._accessibleView?.editorWidget;
        editorWidget?.setPosition(position);
        if (reveal) {
            editorWidget?.revealLine(position.lineNumber);
        }
    }
};
AccessibleViewService = ( __decorate([
    ( __param(0, IInstantiationService)),
    ( __param(1, IConfigurationService)),
    ( __param(2, IKeybindingService))
], AccessibleViewService));
let AccessibleViewSymbolQuickPick = class AccessibleViewSymbolQuickPick {
    constructor(_accessibleView, _quickInputService) {
        this._accessibleView = _accessibleView;
        this._quickInputService = _quickInputService;
    }
    show(provider) {
        const quickPick = this._quickInputService.createQuickPick();
        quickPick.placeholder = ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'accessibleViewSymbolQuickPickPlaceholder',
            "Type to search symbols"
        ));
        quickPick.title = ( localizeWithPath(
            'vs/workbench/contrib/accessibility/browser/accessibleView',
            'accessibleViewSymbolQuickPickTitle',
            "Go to Symbol Accessible View"
        ));
        const symbols = this._accessibleView.getSymbols();
        if (!symbols) {
            return;
        }
        for (const symbol of symbols) {
        }
        quickPick.canSelectMany = false;
        quickPick.items = symbols;
        quickPick.show();
        quickPick.onDidAccept(() => {
            this._accessibleView.showSymbol(provider, quickPick.selectedItems[0]);
            quickPick.hide();
        });
        quickPick.onDidHide(() => {
            if (quickPick.selectedItems.length === 0) {
                this._accessibleView.show(provider);
            }
        });
    }
};
AccessibleViewSymbolQuickPick = ( __decorate([
    ( __param(1, IQuickInputService))
], AccessibleViewSymbolQuickPick));
function shouldHide(event, keybindingService, configurationService) {
    if (!configurationService.getValue("accessibility.accessibleView.closeOnKeyPress" )) {
        return false;
    }
    const standardKeyboardEvent = ( new StandardKeyboardEvent(event));
    const resolveResult = keybindingService.softDispatch(standardKeyboardEvent, standardKeyboardEvent.target);
    const isValidChord = resolveResult.kind === 1 ;
    if (keybindingService.inChordMode || isValidChord) {
        return false;
    }
    return shouldHandleKey(event) && !event.ctrlKey && !event.altKey && !event.metaKey && !event.shiftKey;
}
function shouldHandleKey(event) {
    return !!event.code.match(/^(Key[A-Z]|Digit[0-9]|Equal|Comma|Period|Slash|Quote|Backquote|Backslash|Minus|Semicolon|Space|Enter)$/);
}
export { AccessibleView, AccessibleViewService, IAccessibleViewService };
