import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import Severity$1 from '../../../../base/common/severity.js';
import { getCodeEditor } from '../../../../editor/browser/editorBrowser.js';
import { IEditorService } from '../../../services/editor/common/editorService.js';
import { ILanguageStatusService } from '../../../services/languageStatus/common/languageStatusService.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { Extensions } from '../../../common/contributions.js';
import { localizeWithPath } from '../../../../nls.js';
import { FoldingController } from '../../../../editor/contrib/folding/browser/folding.js';
import { ColorDetector } from '../../../../editor/contrib/colorPicker/browser/colorDetector.js';
const openSettingsCommand = 'workbench.action.openSettings';
const configureSettingsLabel = ( localizeWithPath(
    'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
    'status.button.configure',
    "Configure"
));
let LimitIndicatorContribution = class LimitIndicatorContribution extends Disposable {
    constructor(editorService, languageStatusService) {
        super();
        const accessors = [( new ColorDecorationAccessor()), ( new FoldingRangeAccessor())];
        const statusEntries = ( accessors.map(indicator => ( new LanguageStatusEntry(languageStatusService, indicator))));
        statusEntries.forEach(entry => this._register(entry));
        let control;
        const onActiveEditorChanged = () => {
            const activeControl = editorService.activeTextEditorControl;
            if (activeControl === control) {
                return;
            }
            control = activeControl;
            const editor = getCodeEditor(activeControl);
            statusEntries.forEach(statusEntry => statusEntry.onActiveEditorChanged(editor));
        };
        this._register(editorService.onDidActiveEditorChange(onActiveEditorChanged));
        onActiveEditorChanged();
    }
};
LimitIndicatorContribution = ( __decorate([
    ( __param(0, IEditorService)),
    ( __param(1, ILanguageStatusService))
], LimitIndicatorContribution));
class ColorDecorationAccessor {
    constructor() {
        this.id = 'decoratorsLimitInfo';
        this.name = ( localizeWithPath(
            'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
            'colorDecoratorsStatusItem.name',
            'Color Decorator Status'
        ));
        this.label = ( localizeWithPath(
            'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
            'status.limitedColorDecorators.short',
            'Color Decorators'
        ));
        this.source = ( localizeWithPath(
            'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
            'colorDecoratorsStatusItem.source',
            'Color Decorators'
        ));
        this.settingsId = 'editor.colorDecoratorsLimit';
    }
    getLimitReporter(editor) {
        return ColorDetector.get(editor)?.limitReporter;
    }
}
class FoldingRangeAccessor {
    constructor() {
        this.id = 'foldingLimitInfo';
        this.name = ( localizeWithPath(
            'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
            'foldingRangesStatusItem.name',
            'Folding Status'
        ));
        this.label = ( localizeWithPath(
            'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
            'status.limitedFoldingRanges.short',
            'Folding Ranges'
        ));
        this.source = ( localizeWithPath(
            'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
            'foldingRangesStatusItem.source',
            'Folding'
        ));
        this.settingsId = 'editor.foldingMaximumRegions';
    }
    getLimitReporter(editor) {
        return FoldingController.get(editor)?.limitReporter;
    }
}
class LanguageStatusEntry {
    constructor(languageStatusService, accessor) {
        this.languageStatusService = languageStatusService;
        this.accessor = accessor;
    }
    onActiveEditorChanged(editor) {
        if (this._indicatorChangeListener) {
            this._indicatorChangeListener.dispose();
            this._indicatorChangeListener = undefined;
        }
        let info;
        if (editor) {
            info = this.accessor.getLimitReporter(editor);
        }
        this.updateStatusItem(info);
        if (info) {
            this._indicatorChangeListener = info.onDidChange(_ => {
                this.updateStatusItem(info);
            });
            return true;
        }
        return false;
    }
    updateStatusItem(info) {
        if (this._limitStatusItem) {
            this._limitStatusItem.dispose();
            this._limitStatusItem = undefined;
        }
        if (info && info.limited !== false) {
            const status = {
                id: this.accessor.id,
                selector: '*',
                name: this.accessor.name,
                severity: Severity$1.Warning,
                label: this.accessor.label,
                detail: ( localizeWithPath(
                    'vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution',
                    'status.limited.details',
                    'only {0} shown for performance reasons',
                    info.limited
                )),
                command: { id: openSettingsCommand, arguments: [this.accessor.settingsId], title: configureSettingsLabel },
                accessibilityInfo: undefined,
                source: this.accessor.source,
                busy: false
            };
            this._limitStatusItem = this.languageStatusService.addStatus(status);
        }
    }
    dispose() {
        this._limitStatusItem = undefined;
        this._indicatorChangeListener = undefined;
    }
}
( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(LimitIndicatorContribution, 3 );
export { LimitIndicatorContribution };
