
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
import { localize } from '../../../../nls.js';
import { VIEWLET_ID } from './files.js';
import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
import { NumberBadge } from '../../../services/activity/common/activity.js';
import { IActivityService } from '../../../services/activity/common/activity.service.js';
import { IWorkingCopyService } from '../../../services/workingCopy/common/workingCopyService.service.js';
import { WorkingCopyCapabilities } from '../../../services/workingCopy/common/workingCopy.js';
import { IFilesConfigurationService } from '../../../services/filesConfiguration/common/filesConfigurationService.service.js';

let DirtyFilesIndicator = class DirtyFilesIndicator extends Disposable {
    static {
        this.ID = "workbench.contrib.dirtyFilesIndicator";
    }
    constructor(activityService, workingCopyService, filesConfigurationService) {
        super();
        this.activityService = activityService;
        this.workingCopyService = workingCopyService;
        this.filesConfigurationService = filesConfigurationService;
        this.badgeHandle = this._register(( new MutableDisposable()));
        this.lastKnownDirtyCount = 0;
        this.updateActivityBadge();
        this.registerListeners();
    }
    registerListeners() {
        this._register(
            this.workingCopyService.onDidChangeDirty(workingCopy => this.onWorkingCopyDidChangeDirty(workingCopy))
        );
    }
    onWorkingCopyDidChangeDirty(workingCopy) {
        const gotDirty = workingCopy.isDirty();
        if (gotDirty && !(workingCopy.capabilities & WorkingCopyCapabilities.Untitled) && this.filesConfigurationService.hasShortAutoSaveDelay(workingCopy.resource)) {
            return;
        }
        if (gotDirty || this.lastKnownDirtyCount > 0) {
            this.updateActivityBadge();
        }
    }
    updateActivityBadge() {
        const dirtyCount = this.lastKnownDirtyCount = this.workingCopyService.dirtyCount;
        if (dirtyCount > 0) {
            this.badgeHandle.value = this.activityService.showViewContainerActivity(VIEWLET_ID, {
                badge: ( new NumberBadge(dirtyCount, num => num === 1 ? ( localize(10628, "1 unsaved file")) : ( localize(10629, "{0} unsaved files", dirtyCount))))
            });
        } else {
            this.badgeHandle.clear();
        }
    }
};
DirtyFilesIndicator = ( __decorate([( __param(0, IActivityService)), ( __param(1, IWorkingCopyService)), ( __param(2, IFilesConfigurationService))], DirtyFilesIndicator));

export { DirtyFilesIndicator };
