"use strict";
// *****************************************************************************
// Copyright (C) 2022 Ericsson and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginUninstallationManager = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@theia/core");
const inversify_1 = require("@theia/core/shared/inversify");
let PluginUninstallationManager = class PluginUninstallationManager {
    constructor() {
        this.onDidChangeUninstalledPluginsEmitter = new core_1.Emitter();
        this.uninstalledPlugins = [];
    }
    get onDidChangeUninstalledPlugins() {
        return this.onDidChangeUninstalledPluginsEmitter.event;
    }
    fireDidChange() {
        this.onDidChangeUninstalledPluginsEmitter.fire(Object.freeze(this.uninstalledPlugins.slice()));
    }
    markAsUninstalled(...pluginIds) {
        let didChange = false;
        for (const id of pluginIds) {
            didChange = this.markOneAsUninstalled(id) || didChange;
        }
        if (didChange) {
            this.fireDidChange();
        }
        return didChange;
    }
    markOneAsUninstalled(pluginId) {
        if (!this.uninstalledPlugins.includes(pluginId)) {
            this.uninstalledPlugins.push(pluginId);
            return true;
        }
        return false;
    }
    markAsInstalled(...pluginIds) {
        let didChange = false;
        for (const id of pluginIds) {
            didChange = this.markOneAsInstalled(id) || didChange;
        }
        if (didChange) {
            this.fireDidChange();
        }
        return didChange;
    }
    markOneAsInstalled(pluginId) {
        let index;
        let didChange = false;
        while ((index = this.uninstalledPlugins.indexOf(pluginId)) !== -1) {
            this.uninstalledPlugins.splice(index, 1);
            didChange = true;
        }
        return didChange;
    }
    isUninstalled(pluginId) {
        return this.uninstalledPlugins.includes(pluginId);
    }
    getUninstalledPluginIds() {
        return Object.freeze(this.uninstalledPlugins.slice());
    }
};
PluginUninstallationManager = (0, tslib_1.__decorate)([
    (0, inversify_1.injectable)()
], PluginUninstallationManager);
exports.PluginUninstallationManager = PluginUninstallationManager;
//# sourceMappingURL=plugin-uninstallation-manager.js.map