import AddShoppingCartIcon from '@mui/icons-material/AddShoppingCart'; import ShoppingCartCheckoutIcon from '@mui/icons-material/ShoppingCartCheckout'; import { Avatar, Box, Button, Chip, Stack, Typography } from '@mui/material'; import type { TPaymentCurrency, TPrice } from '@blocklet/payment-types'; import { useLocaleContext } from '@arcblock/ux/lib/Locale/context'; import { formatDynamicUnitPrice, tSafe, INTERVAL_LOCALE_KEY, primaryContrastColor } from '../../utils/format'; interface CrossSellCardProps { crossSellItem: TPrice; currency: TPaymentCurrency | null; exchangeRate: string | null; crossSellRequired: boolean; onAdd: () => Promise; } export default function CrossSellCard({ crossSellItem, currency, exchangeRate, crossSellRequired, onAdd, }: CrossSellCardProps) { const { t } = useLocaleContext(); if (!crossSellItem) return null; const { product } = crossSellItem as any; const productImage = product?.images?.[0] || ''; const productName = product?.name || t('payment.checkout.cross_sell.add'); const { recurring } = crossSellItem as any; const intervalKey = recurring?.interval ? INTERVAL_LOCALE_KEY[recurring.interval] : null; // Show interval label (e.g. "monthly") instead of description when description repeats title const rawDescription = product?.description || ''; const subtitle = (() => { if (rawDescription && rawDescription !== productName) return rawDescription; return intervalKey ? t(intervalKey) : ''; })(); return ( {/* Recommended badge — top-right, matching product-item-card */} {crossSellRequired && ( primaryContrastColor(theme), boxShadow: '0 4px 12px rgba(45,124,243,0.2)', '& .MuiChip-label': { px: 1.5 }, }} /> )} (theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.15)' : 'rgba(45,124,243,0.25)'), boxShadow: (theme) => theme.palette.mode === 'dark' ? '0 12px 40px -8px rgba(0,0,0,0.3)' : '0 12px 40px -8px rgba(0,0,0,0.06)', transition: 'all 0.3s ease', cursor: 'pointer', '&:hover': { borderColor: 'primary.main', boxShadow: '0 12px 40px -8px rgba(0,0,0,0.1)', }, }} onClick={onAdd}> {/* Product avatar */} {productImage ? ( ) : ( (theme.palette.mode === 'dark' ? 'rgba(255,255,255,0.06)' : '#eff6ff'), flexShrink: 0, }}> )} {productName} {formatDynamicUnitPrice(crossSellItem as any, currency, exchangeRate)} {currency?.symbol} {exchangeRate && (crossSellItem as any).base_amount && ( ≈ ${Number((crossSellItem as any).base_amount || 0).toFixed(2)} )} {subtitle && ( {subtitle} )} ); }