"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WalkthroughsContributionPoint = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_components_1 = require("@opensumi/ide-components");
const ide_core_browser_1 = require("@opensumi/ide-core-browser");
const ide_core_common_1 = require("@opensumi/ide-core-common");
const ide_editor_1 = require("@opensumi/ide-editor");
const browser_1 = require("@opensumi/ide-editor/lib/browser");
const common_1 = require("../../../common");
const walkthroughs_view_1 = require("../../components/walkthroughs-view");
const walkthroughs_service_1 = require("../../walkthroughs.service");
let WalkthroughsContributionPoint = class WalkthroughsContributionPoint extends common_1.VSCodeContributePoint {
    contribute() {
        this.addDispose(this.walkthroughsService.onDidAddWalkthrough((w) => this.registerWalkthroughEditor(w)));
        this.addDispose(this.resourceService.registerResourceProvider({
            scheme: ide_core_common_1.Schemes.walkThrough,
            provideResource: async (uri) => ({
                uri,
                icon: (0, ide_components_1.getIcon)('smile'),
                supportsRevive: false,
                name: (0, ide_core_common_1.localize)('walkthroughs.welcome'),
            }),
        }));
        this.addDispose(this.walkthroughsService.onDidOpenWalkthrough(async (id) => {
            const walkthrough = this.walkthroughsService.getWalkthrough(id);
            if (!walkthrough) {
                return;
            }
            await this.commandService.executeCommand(ide_core_browser_1.EDITOR_COMMANDS.OPEN_RESOURCE.id, ide_core_common_1.URI.from({
                scheme: ide_core_common_1.Schemes.walkThrough,
                authority: walkthrough.source,
                query: walkthrough.id,
                path: '/' + walkthrough.id,
            }), {
                disableNavigate: true,
                preview: false,
                forceOpenType: {
                    type: 'component',
                    componentId: this.toComponentId(walkthrough.id),
                },
            });
        }));
        for (const contrib of this.contributesMap) {
            const { extensionId, contributes } = contrib;
            if (!contributes.length) {
                return;
            }
            for (const walkthrough of contributes) {
                this.walkthroughsService.registerExtensionWalkthroughContributions(extensionId, walkthrough);
            }
        }
    }
    toComponentId(id) {
        return `${ide_core_common_1.CUSTOM_EDITOR_SCHEME}-${id}`;
    }
    registerWalkthroughEditor(description) {
        this.addDispose(this.editorComponentRegistry.registerEditorComponent({
            uid: this.toComponentId(description.id),
            component: walkthroughs_view_1.WalkthroughsEditorView,
            scheme: ide_core_common_1.Schemes.walkThrough,
        }));
        this.addDispose(this.editorComponentRegistry.registerEditorComponentResolver(ide_core_common_1.Schemes.walkThrough, (_, __, resolve) => {
            resolve([
                {
                    type: browser_1.EditorOpenType.component,
                    componentId: this.toComponentId(description.id),
                },
            ]);
        }));
    }
};
exports.WalkthroughsContributionPoint = WalkthroughsContributionPoint;
tslib_1.__decorate([
    (0, di_1.Autowired)(browser_1.EditorComponentRegistry),
    tslib_1.__metadata("design:type", browser_1.EditorComponentRegistry)
], WalkthroughsContributionPoint.prototype, "editorComponentRegistry", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(walkthroughs_service_1.WalkthroughsService),
    tslib_1.__metadata("design:type", walkthroughs_service_1.WalkthroughsService)
], WalkthroughsContributionPoint.prototype, "walkthroughsService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_editor_1.ResourceService),
    tslib_1.__metadata("design:type", ide_editor_1.ResourceService)
], WalkthroughsContributionPoint.prototype, "resourceService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_core_common_1.CommandService),
    tslib_1.__metadata("design:type", Object)
], WalkthroughsContributionPoint.prototype, "commandService", void 0);
exports.WalkthroughsContributionPoint = WalkthroughsContributionPoint = tslib_1.__decorate([
    (0, di_1.Injectable)(),
    (0, common_1.Contributes)('walkthroughs'),
    (0, common_1.LifeCycle)(3 /* LifeCyclePhase.Starting */)
], WalkthroughsContributionPoint);
//# sourceMappingURL=walkthroughs.js.map