"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExtHostMessage = void 0;
const common_1 = require("@opensumi/ide-overlay/lib/common");
const vscode_1 = require("../../../common/vscode");
class ExtHostMessage {
    constructor(rpc) {
        this.proxy = rpc.getProxy(vscode_1.MainThreadAPIIdentifier.MainThreadMessages);
    }
    async showMessage(type, rawMessage, optionsOrFirstItem, from, ...rest) {
        let message = rawMessage;
        if (message.length > common_1.MAX_MESSAGE_LENGTH) {
            message = `${rawMessage.substr(0, common_1.MAX_MESSAGE_LENGTH)}...`;
        }
        const options = {};
        const actions = [];
        const items = [];
        const pushItem = (item) => {
            items.push(item);
            if (typeof item === 'string') {
                actions.push(item);
            }
            else {
                actions.push(item.title);
            }
        };
        if (optionsOrFirstItem) {
            if (typeof optionsOrFirstItem === 'string' || 'title' in optionsOrFirstItem) {
                pushItem(optionsOrFirstItem);
            }
            else {
                if ('modal' in optionsOrFirstItem) {
                    options.modal = optionsOrFirstItem.modal;
                    if ('detail' in optionsOrFirstItem) {
                        options.detail = optionsOrFirstItem.detail;
                    }
                }
            }
        }
        for (const item of rest) {
            pushItem(item);
        }
        const actionHandle = await this.proxy.$showMessage(type, message, options, actions, from);
        return actionHandle !== undefined ? items[actionHandle] : undefined;
    }
}
exports.ExtHostMessage = ExtHostMessage;
//# sourceMappingURL=ext.host.message.js.map