"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewsContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const ide_main_layout_1 = require("@opensumi/ide-main-layout");
const welcome_view_1 = require("@opensumi/ide-main-layout/lib/browser/welcome.view");
const common_1 = require("../../../common");
const extension_webview_view_1 = require("../../components/extension-webview-view");
let ViewsContributionPoint = class ViewsContributionPoint extends common_1.VSCodeContributePoint {
    constructor() {
        super(...arguments);
        this.disposableCollection = new ide_core_browser_1.DisposableCollection();
    }
    contribute() {
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            for (const location of Object.keys(contributes)) {
                const views = contributes[location].map((view) => ({
                    ...view,
                    name: this.getLocalizeFromNlsJSON(view.name, extensionId),
                    component: view.type === 'webview' ? extension_webview_view_1.ExtensionWebviewView : welcome_view_1.WelcomeView,
                }));
                for (const view of views) {
                    const handlerId = this.mainLayoutService.collectViewComponent(view, location, { viewId: view.id }, {
                        fromExtension: true,
                    });
                    this.disposableCollection.push({
                        dispose: () => {
                            const handler = this.mainLayoutService.getTabbarHandler(handlerId);
                            handler === null || handler === void 0 ? void 0 : handler.disposeView(view.id);
                        },
                    });
                }
            }
        }
    }
    dispose() {
        this.disposableCollection.dispose();
    }
};
exports.ViewsContributionPoint = ViewsContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_main_layout_1.IMainLayoutService),
    tslib_1.__metadata("design:type", Object)
], ViewsContributionPoint.prototype, "mainLayoutService", void 0);
exports.ViewsContributionPoint = ViewsContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('views'),
    (0, common_1.LifeCycle)(2 /* LifeCyclePhase.Initialize */)
], ViewsContributionPoint);
//# sourceMappingURL=views.js.map