"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewContainersContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_ai_native_1 = require("@opensumi/ide-ai-native");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const ide_main_layout_1 = require("@opensumi/ide-main-layout");
const ide_theme_1 = require("@opensumi/ide-theme");
const common_1 = require("../../../common");
const types_1 = require("../../types");
let ViewContainersContributionPoint = class ViewContainersContributionPoint extends common_1.VSCodeContributePoint {
    constructor() {
        super(...arguments);
        this.disposableCollection = new ide_core_common_1.DisposableCollection();
    }
    convertLocationToSide(location) {
        switch (location) {
            case 'activitybar': {
                return ['left', 'vertical'];
            }
            case 'ai-chat': {
                return [ide_ai_native_1.AI_CHAT_VIEW_ID, 'vertical'];
            }
            default:
                return ['bottom', 'horizontal'];
        }
    }
    contribute() {
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            const extension = this.extensionManageService.getExtensionInstanceByExtId(extensionId);
            if (!extension) {
                continue;
            }
            for (const location of Object.keys(contributes)) {
                const [side, alignment] = this.convertLocationToSide(location);
                for (const container of contributes[location]) {
                    const handlerId = this.mainlayoutService.collectTabbarComponent([], {
                        iconClass: this.toIconClass(container.icon, ide_theme_1.IconType.Mask, extension.path),
                        title: this.getLocalizeFromNlsJSON(container.title, extensionId),
                        containerId: container.id,
                        // 插件注册的视图默认在最后
                        priority: 0,
                        fromExtension: true,
                        // 插件注册的视图容器无view时默认都隐藏tab
                        hideIfEmpty: true,
                        alignment,
                    }, side);
                    this.disposableCollection.push({
                        dispose: () => {
                            const handler = this.mainlayoutService.getTabbarHandler(handlerId);
                            handler === null || handler === void 0 ? void 0 : handler.dispose();
                        },
                    });
                }
            }
        }
    }
    dispose() {
        this.disposableCollection.dispose();
    }
    getViewsMap(contributes) {
        const views = contributes.views;
        const map = {};
        if (views) {
            for (const containerId of Object.keys(views)) {
                if (views[containerId] && Array.isArray(views[containerId])) {
                    map[containerId] = views[containerId].map((view) => view.id);
                }
            }
        }
        return map;
    }
};
exports.ViewContainersContributionPoint = ViewContainersContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_main_layout_1.IMainLayoutService),
    tslib_1.__metadata("design:type", Object)
], ViewContainersContributionPoint.prototype, "mainlayoutService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_theme_1.IIconService),
    tslib_1.__metadata("design:type", Object)
], ViewContainersContributionPoint.prototype, "iconService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(types_1.AbstractExtInstanceManagementService),
    tslib_1.__metadata("design:type", types_1.AbstractExtInstanceManagementService)
], ViewContainersContributionPoint.prototype, "extensionManageService", void 0);
exports.ViewContainersContributionPoint = ViewContainersContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('viewsContainers'),
    (0, common_1.LifeCycle)(2 /* LifeCyclePhase.Initialize */)
], ViewContainersContributionPoint);
//# sourceMappingURL=view-containers.js.map