"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolbarContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const toolbar_1 = require("@opensumi/ide-core-browser/lib/extensions/schema/toolbar");
const common_1 = require("../../../common");
const types_1 = require("../../types");
const main_thread_toolbar_1 = require("../main.thread.toolbar");
let ToolbarContributionPoint = class ToolbarContributionPoint extends common_1.VSCodeContributePoint {
    toLocalized(action, props, extensionId) {
        return props.reduce((pre, cur) => {
            if (pre[cur]) {
                pre[cur] = this.getLocalizeFromNlsJSON(pre[cur], extensionId);
            }
            return pre;
        }, action);
    }
    contribute() {
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            const extension = this.extensionManageService.getExtensionInstanceByExtId(extensionId);
            if (!extension) {
                continue;
            }
            if (contributes.groups) {
                for (const group of contributes.groups) {
                    this.addDispose(this.toolbarRegistry.registerToolbarActionGroup({
                        id: group.id,
                        preferredLocation: group.preferredLocation,
                        weight: group.weight,
                    }));
                }
            }
            if (contributes.actions) {
                for (const toolbarAction of contributes.actions) {
                    switch (toolbarAction.type) {
                        case 'button':
                            this.addDispose(this.kaitianExtToolbarService.registerToolbarButton(extensionId, extension.path, this.toLocalized(toolbarAction, ['title'], extensionId)));
                            break;
                        case 'select':
                            this.addDispose(this.kaitianExtToolbarService.registerToolbarSelect(extensionId, extension.path, this.toLocalized(toolbarAction, ['description'], extensionId)));
                            break;
                        case 'dropdownButton':
                            this.addDispose(this.kaitianExtToolbarService.registerToolbarDropdownButton(extensionId, extension.path, this.toLocalized(toolbarAction, ['description'], extensionId)));
                            break;
                    }
                }
            }
        }
    }
};
exports.ToolbarContributionPoint = ToolbarContributionPoint;
ToolbarContributionPoint.schema = toolbar_1.toolbar.schema;
tslib_1.__decorate([
    (0, di_1.Autowired)(),
    tslib_1.__metadata("design:type", main_thread_toolbar_1.KaitianExtensionToolbarService)
], ToolbarContributionPoint.prototype, "kaitianExtToolbarService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_browser_1.IToolbarRegistry),
    tslib_1.__metadata("design:type", Object)
], ToolbarContributionPoint.prototype, "toolbarRegistry", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(types_1.AbstractExtInstanceManagementService),
    tslib_1.__metadata("design:type", types_1.AbstractExtInstanceManagementService)
], ToolbarContributionPoint.prototype, "extensionManageService", void 0);
exports.ToolbarContributionPoint = ToolbarContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('toolbar'),
    (0, common_1.LifeCycle)(3 /* LifeCyclePhase.Starting */)
], ToolbarContributionPoint);
//# sourceMappingURL=toolbar.js.map