"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssistantMessage = AssistantMessage;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const cn_1 = require("../../../utils/cn.js");
const messageTypeRegistry_1 = require("../../../utils/messageTypeRegistry.js");
const messageUtils_1 = require("../../../utils/messageUtils.js");
const BaseMessage_1 = require("../../molecules/BaseMessage/index.js");
const defaultMessageTypeRegistry_1 = require("./defaultMessageTypeRegistry.js");
require("./AssistantMessage.css");
const b = (0, cn_1.block)('assistant-message');
function AssistantMessage({ content, actions, extraInfo, timestamp, id, messageRendererRegistry, transformOptions, shouldParseIncompleteMarkdown, showActionsOnHover, showTimestamp, userRating, className, qa, onActionPopup, }) {
    const registry = (0, react_1.useMemo)(() => {
        const defaultRegistry = (0, defaultMessageTypeRegistry_1.createDefaultMessageRegistry)(transformOptions, shouldParseIncompleteMarkdown);
        if (messageRendererRegistry) {
            return (0, messageTypeRegistry_1.mergeMessageRendererRegistries)(defaultRegistry, messageRendererRegistry);
        }
        return defaultRegistry;
    }, [messageRendererRegistry, transformOptions, shouldParseIncompleteMarkdown]);
    const parts = (0, messageUtils_1.normalizeContent)(content);
    if (parts.length === 0) {
        return null;
    }
    const renderPart = (part, partIndex) => {
        const PartComponent = (0, messageTypeRegistry_1.getMessageRenderer)(registry, part.type);
        if (!PartComponent) {
            return null;
        }
        const key = part.id || `${id || 'message'}-part-${partIndex}`;
        return (0, jsx_runtime_1.jsx)(PartComponent, { part: part }, key);
    };
    return ((0, jsx_runtime_1.jsx)(BaseMessage_1.BaseMessage, { role: "assistant", actions: actions, extraInfo: extraInfo, showActionsOnHover: showActionsOnHover, showTimestamp: showTimestamp, timestamp: timestamp, userRating: userRating, className: b(null, className), qa: qa, onActionPopup: onActionPopup, children: (0, jsx_runtime_1.jsx)("div", { className: b('content'), children: parts.map((part, index) => renderPart(part, index)) }) }));
}
//# sourceMappingURL=AssistantMessage.js.map
