"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const hljs = require("highlight.js");
const JSON5 = require("json5");
const message_1 = require("./message");
/**
 * MethodMessage is a reply in response to a method to or from the iframe.
 */
class ReplyMessage {
    constructor(kind, data) {
        this.kind = kind;
        this.data = data;
        /**
         * @override
         */
        this.id = String(Math.random());
        const otherKind = kind === message_1.Message.ReceivedReply ? message_1.Message.SentMethod : message_1.Message.ReceivedMethod;
        this.inReplyTo = `${otherKind}-${data.id}`;
        this.text = data.error
            ? message_1.messageLine('reply:error', data.error)
            : message_1.messageLine('reply:ok', data.result);
    }
    /**
     * @override
     */
    expansion() {
        const { value } = hljs.highlight('js', JSON5.stringify({
            type: 'reply',
            result: this.data.result,
            error: this.data.error,
        }, null, 2));
        return `<pre class="hljs"><code>${value}</pre></code>`;
    }
}
exports.ReplyMessage = ReplyMessage;
