"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtHostLayout = exports.TabbarHandler = void 0;
exports.createLayoutAPIFactory = createLayoutAPIFactory;
const ide_core_common_1 = require("@opensumi/ide-core-common");
const sumi_1 = require("../../../common/sumi");
class TabbarHandler {
    constructor(id, proxy) {
        this.id = id;
        this.proxy = proxy;
        this.onActivateEmitter = new ide_core_common_1.Emitter();
        this.onActivate = this.onActivateEmitter.event;
        this.onInActivateEmitter = new ide_core_common_1.Emitter();
        this.onInActivate = this.onInActivateEmitter.event;
    }
    setTitle(title) {
        this.proxy.$setTitle(this.id, title);
    }
    setIcon(iconPath) {
        this.proxy.$setIcon(this.id, iconPath);
    }
    setSize(size) {
        this.proxy.$setSize(this.id, size);
    }
    activate() {
        this.proxy.$activate(this.id);
    }
    deactivate() {
        this.proxy.$deactivate(this.id);
    }
    setVisible(visible) {
        this.proxy.$setVisible(this.id, visible);
    }
    setBadge(badge) {
        this.proxy.$setBadge(this.id, badge);
    }
    isAttached() {
        return this.proxy.$isAttached(this.id);
    }
}
exports.TabbarHandler = TabbarHandler;
class ExtHostLayout {
    constructor(rpcProtocol) {
        this.rpcProtocol = rpcProtocol;
        this.handles = new Map();
        this.rpcProtocol = rpcProtocol;
        this.proxy = this.rpcProtocol.getProxy(sumi_1.MainThreadSumiAPIIdentifier.MainThreadLayout);
    }
    getTabbarHandler(id) {
        if (!this.handles.has(id)) {
            this.proxy.$connectTabbar(id);
            this.handles.set(id, new TabbarHandler(id, this.proxy));
        }
        return this.handles.get(id);
    }
    $acceptMessage(id, type) {
        const handle = this.handles.get(id);
        if (type === 'activate') {
            handle.onActivateEmitter.fire();
        }
        else if (type === 'deactivate') {
            handle.onInActivateEmitter.fire();
        }
    }
}
exports.ExtHostLayout = ExtHostLayout;
function createLayoutAPIFactory(extHostCommands, kaitianLayout, extension) {
    return {
        toggleBottomPanel: async (size) => await extHostCommands.executeCommand('main-layout.bottom-panel.toggle', undefined, size),
        toggleLeftPanel: async (size) => await extHostCommands.executeCommand('main-layout.left-panel.toggle', undefined, size),
        toggleRightPanel: async (size) => await extHostCommands.executeCommand('main-layout.right-panel.toggle', undefined, size),
        showRightPanel: async (size) => await extHostCommands.executeCommand('main-layout.right-panel.toggle', true, size),
        hideRightPanel: async () => await extHostCommands.executeCommand('main-layout.right-panel.toggle', false),
        activatePanel: async (id) => await extHostCommands.executeCommand(`workbench.view.extension.${id}`),
        isBottomPanelVisible: async () => await extHostCommands.executeCommand('main-layout.bottom-panel.is-visible'),
        isLeftPanelVisible: async () => await extHostCommands.executeCommand('main-layout.left-panel.is-visible'),
        isRightPanelVisible: async () => await extHostCommands.executeCommand('main-layout.right-panel.is-visible'),
        getTabbarHandler: (id) => kaitianLayout.getTabbarHandler(extension.id + ':' + id),
        // 为了获取其他插件注册的tabbarHandler
        getExtensionTabbarHandler: (id, extensionId) => {
            if (extensionId) {
                return kaitianLayout.getTabbarHandler(extensionId + ':' + id);
            }
            else {
                return kaitianLayout.getTabbarHandler(id);
            }
        },
    };
}
//# sourceMappingURL=ext.host.layout.js.map