"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MainThreadOutput = void 0;
const tslib_1 = require("tslib");
const di_1 = require("@opensumi/di");
const ide_main_layout_1 = require("@opensumi/ide-main-layout");
const output_service_1 = require("@opensumi/ide-output/lib/browser/output.service");
let MainThreadOutput = class MainThreadOutput {
    constructor() {
        this.channels = new Map();
    }
    dispose() {
        this.channels.forEach((channel) => {
            this.outputService.deleteChannel(channel.name);
        });
        this.channels.clear();
    }
    $replace(channelName, value) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            outputChannel.clear();
            outputChannel.append(value);
        }
        return Promise.resolve();
    }
    $append(channelName, value) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            outputChannel.append(value);
        }
        return Promise.resolve();
    }
    $appendLine(channelName, value) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            outputChannel.appendLine(value);
        }
        return Promise.resolve();
    }
    $clear(channelName) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            outputChannel.clear();
        }
        return Promise.resolve();
    }
    $dispose(channelName) {
        this.outputService.deleteChannel(channelName);
        if (this.channels.has(channelName)) {
            this.channels.delete(channelName);
        }
        return Promise.resolve();
    }
    async $reveal(channelName, preserveFocus) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            outputChannel.setVisibility(true);
            this.outputService.updateSelectedChannel(outputChannel);
        }
    }
    $close(channelName) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            outputChannel.setVisibility(false);
        }
        return Promise.resolve();
    }
    getChannel(channelName) {
        let outputChannel;
        if (this.channels.has(channelName)) {
            outputChannel = this.channels.get(channelName);
        }
        else {
            outputChannel = this.outputService.getChannel(channelName);
            this.channels.set(channelName, outputChannel);
        }
        return outputChannel;
    }
    async $setLanguageId(channelName, languageId) {
        const outputChannel = this.getChannel(channelName);
        if (outputChannel) {
            await outputChannel.setLanguageId(languageId);
        }
    }
};
exports.MainThreadOutput = MainThreadOutput;
tslib_1.__decorate([
    (0, di_1.Autowired)(output_service_1.OutputService),
    tslib_1.__metadata("design:type", output_service_1.OutputService)
], MainThreadOutput.prototype, "outputService", void 0);
tslib_1.__decorate([
    (0, di_1.Autowired)(ide_main_layout_1.IMainLayoutService),
    tslib_1.__metadata("design:type", Object)
], MainThreadOutput.prototype, "layoutService", void 0);
exports.MainThreadOutput = MainThreadOutput = tslib_1.__decorate([
    (0, di_1.Injectable)({ multiple: true })
], MainThreadOutput);
//# sourceMappingURL=main.thread.output.js.map