import $i18n from '../../../../../locales/i18n.js';
import React from 'react';
import ReactMarkdown from 'react-markdown';
import remarkGfm from 'remark-gfm';
import { CnTextEllipsis } from '@cainiaofe/cn-ui';
import { markdownComponents2 } from '../../../../../cn-ai-agent/view/components';
import { useTypewriter } from '../../../../../cn-ai-agent/hooks/use-typewriter';
/**
 * 纯内容渲染组件 —— 仅输出 Markdown / loading / error / 刷新入口，
 * 不包含 AiSummary 的外壳（badge、wrapper 视觉容器）。
 */
export const AiSummaryContent = ({ status, summary, onRefresh, useMarkdown = false, showRefreshButton = true, collapsed = false, classNamePrefix = '', typewriter = false, typewriterSpeed = 30, }) => {
    const typewriterEnabled = typewriter && status === 'done' && !collapsed;
    const displayText = useTypewriter(summary, {
        speed: typewriterSpeed,
        enabled: typewriterEnabled,
    });
    const visibleText = typewriterEnabled ? displayText : summary;
    const isTyping = typewriterEnabled && visibleText.length < (summary || '').length;
    const handleRefresh = React.useCallback(() => {
        if (status === 'loading')
            return;
        onRefresh === null || onRefresh === void 0 ? void 0 : onRefresh();
    }, [status, onRefresh]);
    const shouldUseMarkdown = useMarkdown && status === 'done';
    const renderSummaryText = () => {
        if (shouldUseMarkdown) {
            if (collapsed) {
                return (React.createElement(CnTextEllipsis, { line: 1, hasTooltip: false },
                    React.createElement(ReactMarkdown, { remarkPlugins: [remarkGfm], components: markdownComponents2, className: "markdown-body" }, summary || '')));
            }
            return (React.createElement(ReactMarkdown, { remarkPlugins: [remarkGfm], components: markdownComponents2, className: "markdown-body" }, visibleText || ''));
        }
        return (React.createElement(CnTextEllipsis, { line: collapsed ? 1 : 10000, hasTooltip: false }, visibleText || ''));
    };
    if (status === 'loading' && !summary) {
        return (React.createElement("span", { className: `${classNamePrefix}ai-summary-content-loading` },
            React.createElement("span", { className: `${classNamePrefix}ai-summary-loading-dot` }, "\u25CF"),
            React.createElement("span", null, $i18n.get({ id: 'Analyzing', dm: '正在分析...' }))));
    }
    return (React.createElement(React.Fragment, null,
        renderSummaryText(),
        isTyping && React.createElement("span", { className: `${classNamePrefix}ai-summary-cursor` }, "\u258D"),
        showRefreshButton && status === 'done' && !collapsed && !isTyping && (React.createElement("span", { className: `${classNamePrefix}ai-summary-refresh`, onClick: handleRefresh }, $i18n.get({ id: 'Regenerate', dm: '重新生成' })))));
};
export default AiSummaryContent;
