"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageItem = void 0;
const react_1 = __importDefault(require("react"));
const react_markdown_1 = __importDefault(require("react-markdown"));
const remark_gfm_1 = __importDefault(require("remark-gfm"));
const use_typewriter_1 = require("../../hooks/use-typewriter");
const markdown_components_1 = require("./markdown-components");
/**
 * 消息项组件（支持逐字显示效果）
 */
const MessageItem = ({ message, isGenerating = false }) => {
    // 对于正在生成的助手消息，使用逐字显示效果
    // 注意：Hook 必须无条件调用，通过 enabled 参数控制是否启用
    const typewriterContent = (0, use_typewriter_1.useTypewriter)(message.content, {
        speed: 30,
        enabled: message.role === 'assistant' && isGenerating,
    });
    // 如果未启用逐字显示，直接使用原始内容
    const displayContent = message.role === 'assistant' && isGenerating ? typewriterContent : message.content;
    const renderMarkdown = (text) => (react_1.default.createElement(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], components: markdown_components_1.markdownComponents }, text));
    const renderAssistantContent = () => renderMarkdown(displayContent || '');
    return (react_1.default.createElement("div", { className: `cn-ai-agent__message cn-ai-agent__message--${message.role}` }, message.role === 'assistant' ? (react_1.default.createElement("div", { className: "cn-ai-agent__message-content" }, renderAssistantContent())) : (react_1.default.createElement("div", { className: "cn-ai-agent__message-text" }, displayContent || ''))));
};
exports.MessageItem = MessageItem;
exports.MessageItem.displayName = 'MessageItem';
