'use strict';

const index = require('./index-2e5758b6.js');
const chat = require('./chat-a1c8f378.js');

const renderLink = (content) => {
    return (index.h("a", { class: "link", href: content, target: "_blank", rel: "noopener noreferrer" }, content));
};
const renderBold = (content) => {
    if (typeof content === 'string') {
        return index.h("b", null, content);
    }
    return index.h("b", null, renderTokens(content));
};
const renderItalic = (content) => {
    if (typeof content === 'string') {
        return index.h("i", null, content);
    }
    return index.h("i", null, renderTokens(content));
};
const renderStrikethrough = (content) => {
    if (typeof content === 'string') {
        return index.h("s", null, content);
    }
    return index.h("b", null, renderTokens(content));
};
const renderPlainText = (content) => {
    if (typeof content === 'string') {
        return content;
    }
    return index.h("p", null, renderTokens(content));
};
const renderTokens = (tokens) => {
    return tokens.map((token) => {
        switch (token.type) {
            case 'a':
                if (typeof token.content === 'string') {
                    return renderLink(token.content);
                }
            case 'b':
                return renderBold(token.content);
            case 'i':
                return renderItalic(token.content);
            case 's':
                return renderStrikethrough(token.content);
            case 'q':
                return index.h("span", { class: "block-quote" });
            case 'plain_text':
            default:
                return renderPlainText(token.content);
        }
    });
};
const TextMessageView = ({ message }) => {
    const slicedMessage = message.slice(0, chat.MAX_TEXT_LENGTH);
    const withReply = chat.extractReplyBlock(slicedMessage, true);
    const withoutReply = chat.stripOutReplyBlock(slicedMessage);
    return (index.h("p", null,
        withReply.length !== 0 && (index.h("blockquote", null, withReply.split('\n').map((line) => {
            const tokens = chat.parseRichText(line);
            return index.h("p", null, renderTokens(tokens));
        }))),
        withoutReply.split('\n').map((line) => {
            const tokens = chat.parseRichText(line);
            return index.h("p", null, renderTokens(tokens));
        })));
};

exports.TextMessageView = TextMessageView;
