import React from 'react';
import { useAiTableIcons } from '../../../../../cn-ai-table/view/hooks/use-ai-table-icons';
import { CnIcon } from '@cainiaofe/cn-ui';
import { AiSummaryContent } from './ai-summary-content';
import './ai-summary.scss';
/**
 * AI 总结组件（纯展示，由外部控制状态）
 * 配合 useSummaryPolling hook 使用
 */
export const AiSummary = ({ status, summary, onRefresh, useMarkdown = false, showRefreshButton = true, classNamePrefix = '', typewriter = false, typewriterSpeed, }) => {
    const icons = useAiTableIcons();
    const [collapsed, setCollapsed] = React.useState(false);
    const toggleCollapsed = React.useCallback(() => {
        setCollapsed((prev) => !prev);
    }, []);
    const renderContent = () => {
        if (status === 'done' || status === 'error' || status === 'loading') {
            return (React.createElement("div", { className: `${classNamePrefix}ai-summary-result ${collapsed ? `${classNamePrefix}ai-summary-result--collapsed` : ''}` },
                React.createElement("div", { className: `${classNamePrefix}ai-summary-result-badge`, onClick: toggleCollapsed, role: "button", tabIndex: 0 },
                    React.createElement("img", { src: icons.FIELD_AI, alt: "AI" }),
                    React.createElement("span", null, "AI"),
                    React.createElement(CnIcon, { type: collapsed ? 'triangle-down-fill' : 'triangle-up-fill', size: "medium" })),
                React.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.createElement(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.createElement("div", { className: wrapperClass }, renderContent());
};
export default AiSummary;
