"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AiSummary = void 0;
const react_1 = __importDefault(require("react"));
const use_ai_table_icons_1 = require("../../../../../cn-ai-table/view/hooks/use-ai-table-icons");
const cn_ui_1 = require("@cainiaofe/cn-ui");
const ai_summary_content_1 = require("./ai-summary-content");
require("./ai-summary.scss");
/**
 * AI 总结组件（纯展示，由外部控制状态）
 * 配合 useSummaryPolling hook 使用
 */
const AiSummary = ({ status, summary, onRefresh, useMarkdown = false, showRefreshButton = true, classNamePrefix = '', typewriter = false, typewriterSpeed, }) => {
    const icons = (0, use_ai_table_icons_1.useAiTableIcons)();
    const [collapsed, setCollapsed] = react_1.default.useState(false);
    const toggleCollapsed = react_1.default.useCallback(() => {
        setCollapsed((prev) => !prev);
    }, []);
    const renderContent = () => {
        if (status === 'done' || status === 'error' || status === 'loading') {
            return (react_1.default.createElement("div", { className: `${classNamePrefix}ai-summary-result ${collapsed ? `${classNamePrefix}ai-summary-result--collapsed` : ''}` },
                react_1.default.createElement("div", { className: `${classNamePrefix}ai-summary-result-badge`, onClick: toggleCollapsed, role: "button", tabIndex: 0 },
                    react_1.default.createElement("img", { src: icons.FIELD_AI, alt: "AI" }),
                    react_1.default.createElement("span", null, "AI"),
                    react_1.default.createElement(cn_ui_1.CnIcon, { type: collapsed ? 'triangle-down-fill' : 'triangle-up-fill', size: "medium" })),
                react_1.default.createElement("div", { className: `${classNamePrefix}ai-summary-result-content ${status === 'error' ? `${classNamePrefix}ai-summary-result-content--error` : ''} ${status === 'loading' ? `${classNamePrefix}ai-summary-result-content--loading` : ''}` },
                    react_1.default.createElement(ai_summary_content_1.AiSummaryContent, { status: status, summary: summary, onRefresh: onRefresh, useMarkdown: useMarkdown, showRefreshButton: showRefreshButton, collapsed: collapsed, classNamePrefix: classNamePrefix, typewriter: typewriter, typewriterSpeed: typewriterSpeed }))));
        }
    };
    const isResultState = status === 'done' || status === 'error' || status === 'loading';
    const wrapperClass = isResultState
        ? `${classNamePrefix}ai-summary-wrapper ${classNamePrefix}ai-summary-wrapper--result`
        : `${classNamePrefix}ai-summary-wrapper`;
    return react_1.default.createElement("div", { className: wrapperClass }, renderContent());
};
exports.AiSummary = AiSummary;
exports.default = exports.AiSummary;
