import { useEffect, useState } from 'react' import { Modal, Row, Col, Statistic, Spin, message } from 'antd' import { ArrowUpOutlined, ArrowDownOutlined } from '@ant-design/icons' import { apiService } from '../../services/api' import { formatUSDC } from '../../utils' import { useTranslation } from 'react-i18next' import { useMediaQuery } from 'react-responsive' import type { CopyTradingStatistics } from '../../types' interface StatisticsModalProps { open: boolean onClose: () => void copyTradingId: string } const StatisticsModal: React.FC = ({ open, onClose, copyTradingId }) => { const { t } = useTranslation() const isMobile = useMediaQuery({ maxWidth: 768 }) const [loading, setLoading] = useState(false) const [statistics, setStatistics] = useState(null) useEffect(() => { if (open && copyTradingId) { fetchStatistics() } }, [open, copyTradingId]) const fetchStatistics = async () => { if (!copyTradingId) return setLoading(true) try { const response = await apiService.statistics.detail({ copyTradingId: parseInt(copyTradingId) }) if (response.data.code === 0 && response.data.data) { setStatistics(response.data.data) } else { message.error(response.data.msg || t('copyTradingOrders.fetchStatisticsFailed') || '获取统计信息失败') } } catch (error: any) { message.error(error.message || t('copyTradingOrders.fetchStatisticsFailed') || '获取统计信息失败') } finally { setLoading(false) } } const getPnlColor = (value: string): string => { const num = parseFloat(value) if (isNaN(num)) return '#666' return num >= 0 ? '#3f8600' : '#cf1322' } const getPnlIcon = (value: string) => { const num = parseFloat(value) if (isNaN(num)) return null return num >= 0 ? : } return ( {loading ? (
) : !statistics ? (

{t('copyTradingOrders.noStatistics') || '暂无统计数据'}

) : isMobile ? (
{t('copyTradingOrders.totalBuyOrders') || '总买入订单数'}
{statistics.totalBuyOrders}
{t('copyTradingOrders.totalSellOrders') || '总卖出订单数'}
{statistics.totalSellOrders}
{t('copyTradingOrders.totalBuyAmount') || '总买入金额'}
${formatUSDC(statistics.totalBuyAmount)}
{t('copyTradingOrders.totalSellAmount') || '总卖出金额'}
${formatUSDC(statistics.totalSellAmount)}
{t('copyTradingOrders.totalPnl') || '总盈亏'}
{getPnlIcon(statistics.totalPnl)} ${formatUSDC(statistics.totalPnl)}
{t('copyTradingOrders.totalRealizedPnl') || '总已实现盈亏'}
{getPnlIcon(statistics.totalRealizedPnl)} ${formatUSDC(statistics.totalRealizedPnl)}
{t('copyTradingOrders.totalUnrealizedPnl') || '总未实现盈亏'}
{getPnlIcon(statistics.totalUnrealizedPnl)} ${formatUSDC(statistics.totalUnrealizedPnl)}
) : (
} /> } /> $} /> $} /> {getPnlIcon(statistics.totalPnl)} $} /> {getPnlIcon(statistics.totalRealizedPnl)} $} /> {getPnlIcon(statistics.totalUnrealizedPnl)} $} />
)}
) } export default StatisticsModal