import { Disposable } from '../../../../base/common/lifecycle.js';
import { ICodeEditorService } from '../../../browser/services/codeEditorService.js';
import { InlineCompletionContextKeys } from './inlineCompletionContextKeys.js';
import { InlineCompletionsController } from './inlineCompletionsController.js';
import { AccessibleViewType, AccessibleViewProviderId } from '../../../../platform/accessibility/browser/accessibleView.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
class InlineCompletionsAccessibleView extends Disposable {
    getProvider(accessor) {
        const codeEditorService = accessor.get(ICodeEditorService);
        function resolveProvider() {
            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;
            }
            const lineText = model.textModel.getLineContent(state.primaryGhostText.lineNumber);
            const ghostText = state.primaryGhostText.renderForScreenReader(lineText);
            if (!ghostText) {
                return;
            }
            const language = editor.getModel()?.getLanguageId() ?? undefined;
            return {
                id: AccessibleViewProviderId.InlineCompletions,
                verbositySettingKey: 'accessibility.verbosity.inlineCompletions',
                provideContent() { return lineText + ghostText; },
                onClose() {
                    model.stop();
                    editor.focus();
                },
                next() {
                    model.next();
                    setTimeout(() => resolveProvider(), 50);
                },
                previous() {
                    model.previous();
                    setTimeout(() => resolveProvider(), 50);
                },
                options: { language, type: AccessibleViewType.View }
            };
        }
        return resolveProvider();
    }
    constructor() {
        super();
        this.type = AccessibleViewType.View;
        this.priority = 95;
        this.name = 'inline-completions';
        this.when = ( ContextKeyExpr.and(InlineCompletionContextKeys.inlineSuggestionVisible));
    }
}
export { InlineCompletionsAccessibleView };
