import React, { useEffect, useState } from 'react'; import { Typography, Tag, Button, Banner, Skeleton, Spin, Tooltip, Input, InputNumber, } from '@douyinfe/semi-ui'; import { SiAlipay, SiWechat, SiStripe } from 'react-icons/si'; import { CreditCard, WalletCards, Activity, ChartColumn, Receipt, Gift, DollarSign, Ticket, ChevronRight, } from 'lucide-react'; import { useMinimumLoadingTime } from '../../hooks/common/useMinimumLoadingTime'; import { getCurrencyConfig } from '../../helpers/render'; import SubscriptionPlansCard from './SubscriptionPlansCard'; import './preset-amount-card.css'; const { Text } = Typography; const RechargeCard = ({ t, enableOnlineTopUp, enableStripeTopUp, enableCreemTopUp, creemProducts, creemPreTopUp, presetAmounts, selectedPreset, selectPresetAmount, onPresetCardClick, formatLargeNumber, priceRatio, topUpCount, minTopUp, renderTopUpCount, getAmount, setTopUpCount, setSelectedPreset, renderAmount, amountLoading, payMethods, preTopUp, paymentLoading, payWay, redemptionCode, setRedemptionCode, topUp, isSubmitting, topUpLink, openTopUpLink, userState, renderQuota, statusLoading, topupInfo, onOpenHistory, enableAlipayTopUp, enableWechatPayTopUp, enableWaffoTopUp, waffoTopUp, waffoPayMethods, subscriptionLoading = false, subscriptionPlans = [], billingPreference, onChangeBillingPreference, activeSubscriptions = [], allSubscriptions = [], reloadSubscriptionSelf, }) => { const [activeTab, setActiveTab] = useState('topup'); const [customAmount, setCustomAmount] = useState(10); const showAmountSkeleton = useMinimumLoadingTime(amountLoading); const shouldShowSubscription = !subscriptionLoading && subscriptionPlans.length > 0; const statusStr = localStorage.getItem('status'); let usdRate = 7; try { if (statusStr) { const s = JSON.parse(statusStr); usdRate = s?.usd_exchange_rate || 7; } } catch (e) {} const { symbol, rate, type: currencyType } = getCurrencyConfig(); const calcRmb = (usdAmount) => { return usdAmount * (priceRatio || 1); }; const getDiscountForAmount = (val) => { const preset = presetAmounts.find((p) => p.value === val); if (preset?.discount) return preset.discount; if (topupInfo?.discount?.[val]) return topupInfo.discount[val]; return 1.0; }; const handleCustomAmountChange = (val) => { const num = Number(val); if (!num || num <= 0) return; setCustomAmount(num); setTopUpCount(num); setSelectedPreset(null); getAmount(num); }; const handlePresetClick = (preset) => { const discount = getDiscountForAmount(preset.value); const num = preset.value * discount; setCustomAmount(preset.value); if (onPresetCardClick) { onPresetCardClick(preset); } else { selectPresetAmount(preset); } }; useEffect(() => { if (subscriptionLoading) return; if (shouldShowSubscription) { setActiveTab('subscription'); } }, [shouldShowSubscription, subscriptionLoading]); const isAnyPayEnabled = enableOnlineTopUp || enableStripeTopUp || enableCreemTopUp || enableAlipayTopUp || enableWechatPayTopUp || enableWaffoTopUp; const tabs = [ { key: 'topup', label: t('充值'), desc: t('灵活付费') }, { key: 'subscription', label: t('订阅'), desc: t('享更低单价') }, ]; // 统计卡片配置 const statCards = [ { key: 'balance', icon: WalletCards, label: t('当前余额'), value: userState?.user?.quota, sublabel: t('剩余配额'), highlight: true, }, { key: 'usage', icon: ChartColumn, label: t('总用量'), value: userState?.user?.used_quota, sublabel: t('总消耗额度'), }, { key: 'requests', icon: Activity, label: t('API 请求'), value: userState?.user?.request_count || 0, sublabel: t('总请求数'), raw: true, }, ]; const topupContent = (