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