import { useTranslation } from 'react-i18next'; import { GiftIcon, SendIcon } from '@/components/icons'; import { StatCard } from '@/components/stats'; import { useCurrency } from '../../../hooks/useCurrency'; import type { AdminUserGiftItem, AdminUserGiftsResponse } from '../../../api/adminUsers'; // ────────────────────────────────────────────────────────────────── // Status badge // ────────────────────────────────────────────────────────────────── function GiftStatusBadge({ status }: { status: string }) { const { t } = useTranslation(); const styles: Record = { pending: 'bg-warning-500/20 text-warning-400 border-warning-500/30', paid: 'bg-accent-500/20 text-accent-400 border-accent-500/30', delivered: 'bg-success-500/20 text-success-400 border-success-500/30', pending_activation: 'bg-accent-500/20 text-accent-400 border-accent-500/30', failed: 'bg-error-500/20 text-error-400 border-error-500/30', expired: 'bg-dark-600 text-dark-400 border-dark-500', }; const fallback = 'bg-dark-600 text-dark-400 border-dark-500'; const label = t(`admin.users.detail.gifts.status.${status}`, { defaultValue: '' }) || status; return ( {label} ); } // ────────────────────────────────────────────────────────────────── // Single gift card // ────────────────────────────────────────────────────────────────── function GiftCard({ gift, direction, locale, onNavigateToUser, }: { gift: AdminUserGiftItem; direction: 'sent' | 'received'; locale: string; onNavigateToUser: (userId: number) => void; }) { const { t } = useTranslation(); const { formatWithCurrency } = useCurrency(); const isSent = direction === 'sent'; const otherPartyLabel = isSent ? t('admin.users.detail.gifts.recipient') : t('admin.users.detail.gifts.sender'); const otherPartyName = isSent ? gift.receiver_username ? `@${gift.receiver_username}` : gift.gift_recipient_value || t('admin.users.detail.gifts.codeOnly') : gift.buyer_username ? `@${gift.buyer_username}` : gift.buyer_full_name || t('admin.users.detail.gifts.unknownUser'); const otherPartyId = isSent ? gift.receiver_user_id : gift.buyer_user_id; const dateOpts: Intl.DateTimeFormatOptions = { day: '2-digit', month: '2-digit', year: '2-digit', hour: '2-digit', minute: '2-digit', }; return (
{/* Header */}
{gift.tariff_name || '—'}
{gift.period_days} {t('admin.users.detail.gifts.days')} · {gift.device_limit}{' '} {t('admin.users.detail.gifts.devices')}
{/* Details grid */}
{otherPartyLabel}:{' '} {otherPartyName} {otherPartyId && ( )}
{t('admin.users.detail.gifts.amount')}:{' '} {formatWithCurrency(gift.amount_kopeks / 100)}
{t('admin.users.detail.gifts.paymentMethod')}:{' '} {gift.payment_method || '—'}
{t('admin.users.detail.gifts.createdAt')}:{' '} {gift.created_at ? new Date(gift.created_at).toLocaleString(locale, dateOpts) : '—'}
{gift.paid_at && (
{t('admin.users.detail.gifts.paidAt')}:{' '} {new Date(gift.paid_at).toLocaleString(locale, dateOpts)}
)} {gift.delivered_at && (
{t('admin.users.detail.gifts.deliveredAt')}:{' '} {new Date(gift.delivered_at).toLocaleString(locale, dateOpts)}
)}
{/* Gift message */} {gift.gift_message && (
“{gift.gift_message}”
)} {/* Token */}
GIFT-{gift.token}
); } // ────────────────────────────────────────────────────────────────── // Tab — gifts list with sent + received sections // ────────────────────────────────────────────────────────────────── export interface GiftsTabProps { giftsLoading: boolean; giftsData: AdminUserGiftsResponse | null; locale: string; onNavigateToUser: (userId: number) => void; } export function GiftsTab({ giftsLoading, giftsData, locale, onNavigateToUser }: GiftsTabProps) { const { t } = useTranslation(); if (giftsLoading) { return (
); } if (!giftsData || (giftsData.sent.length === 0 && giftsData.received.length === 0)) { return (

{t('admin.users.detail.gifts.noGifts')}

); } return (
{/* Summary counters */}
} tone="accent" /> } tone="success" />
{/* Sent Gifts */}

{t('admin.users.detail.gifts.sentTitle')} ({giftsData.sent_total})

{giftsData.sent.length === 0 ? (
{t('admin.users.detail.gifts.noSent')}
) : (
{giftsData.sent.map((gift) => ( ))}
)}
{/* Received Gifts */}

{t('admin.users.detail.gifts.receivedTitle')} ({giftsData.received_total})

{giftsData.received.length === 0 ? (
{t('admin.users.detail.gifts.noReceived')}
) : (
{giftsData.received.map((gift) => ( ))}
)}
); }