
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import '../../../../base/common/observableInternal/index.js';
import { registerDiffEditorContribution } from '../../../../editor/browser/editorExtensions.js';
import { EmbeddedDiffEditorWidget } from '../../../../editor/browser/widget/diffEditor/embeddedDiffEditorWidget.js';
import { ITextResourceConfigurationService } from '../../../../editor/common/services/textResourceConfiguration.service.js';
import { localize } from '../../../../nls.js';
import { AccessibleViewRegistry } from '../../../../platform/accessibility/browser/accessibleViewRegistry.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import '../../../../platform/notification/common/notification.js';
import { INotificationService } from '../../../../platform/notification/common/notification.service.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { FloatingEditorClickWidget } from '../../../browser/codeeditor.js';
import { Extensions } from '../../../common/configuration.js';
import { DiffEditorAccessibilityHelp } from './diffEditorAccessibilityHelp.js';
import { observableFromEvent } from '../../../../base/common/observableInternal/observables/observableFromEvent.js';
import { autorunWithStore } from '../../../../base/common/observableInternal/reactions/autorun.js';
import Severity$1 from '../../../../base/common/severity.js';

let DiffEditorHelperContribution = class DiffEditorHelperContribution extends Disposable {
    static {
        this.ID = "editor.contrib.diffEditorHelper";
    }
    constructor(
        _diffEditor,
        _instantiationService,
        _textResourceConfigurationService,
        _notificationService
    ) {
        super();
        this._diffEditor = _diffEditor;
        this._instantiationService = _instantiationService;
        this._textResourceConfigurationService = _textResourceConfigurationService;
        this._notificationService = _notificationService;
        const isEmbeddedDiffEditor = this._diffEditor instanceof EmbeddedDiffEditorWidget;
        if (!isEmbeddedDiffEditor) {
            const computationResult = observableFromEvent(
                this,
                e => this._diffEditor.onDidUpdateDiff(e),
                () =>  this._diffEditor.getDiffComputationResult()
            );
            const onlyWhiteSpaceChange = ( computationResult.map(r => r && !r.identical && r.changes2.length === 0));
            this._register(autorunWithStore((reader, store) => {
                if (onlyWhiteSpaceChange.read(reader)) {
                    const helperWidget = store.add(this._instantiationService.createInstance(
                        FloatingEditorClickWidget,
                        this._diffEditor.getModifiedEditor(),
                        ( localize(8439, "Show Whitespace Differences")),
                        null
                    ));
                    store.add(helperWidget.onClick(() => {
                        this._textResourceConfigurationService.updateValue(
                            this._diffEditor.getModel().modified.uri,
                            "diffEditor.ignoreTrimWhitespace",
                            false
                        );
                    }));
                    helperWidget.render();
                }
            }));
            this._register(this._diffEditor.onDidUpdateDiff(() => {
                const diffComputationResult = this._diffEditor.getDiffComputationResult();
                if (diffComputationResult && diffComputationResult.quitEarly) {
                    this._notificationService.prompt(Severity$1.Warning, ( localize(
                        8440,
                        "The diff algorithm was stopped early (after {0} ms.)",
                        this._diffEditor.maxComputationTime
                    )), [{
                        label: ( localize(8441, "Remove Limit")),
                        run: () => {
                            this._textResourceConfigurationService.updateValue(
                                this._diffEditor.getModel().modified.uri,
                                "diffEditor.maxComputationTime",
                                0
                            );
                        }
                    }], {});
                }
            }));
        }
    }
};
DiffEditorHelperContribution = ( __decorate([( __param(1, IInstantiationService)), ( __param(2, ITextResourceConfigurationService)), ( __param(3, INotificationService))], DiffEditorHelperContribution));
registerDiffEditorContribution(DiffEditorHelperContribution.ID, DiffEditorHelperContribution);
( Registry.as(Extensions.ConfigurationMigration)).registerConfigurationMigrations([{
    key: "diffEditor.experimental.collapseUnchangedRegions",
    migrateFn: (value, accessor) => {
        return [["diffEditor.hideUnchangedRegions.enabled", {
            value
        }], ["diffEditor.experimental.collapseUnchangedRegions", {
            value: undefined
        }]];
    }
}]);
AccessibleViewRegistry.register(( new DiffEditorAccessibilityHelp()));
