/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { useState } from 'react' import { Search, Copy, Check, ChevronLeft, ChevronRight } from 'lucide-react' import { useTranslation } from 'react-i18next' import { formatCurrencyFromUSD } from '@/lib/currency' import { formatNumber } from '@/lib/format' import { useCopyToClipboard } from '@/hooks/use-copy-to-clipboard' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { ScrollArea } from '@/components/ui/scroll-area' import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { Skeleton } from '@/components/ui/skeleton' import { StatusBadge } from '@/components/status-badge' import { useBillingHistory } from '../../hooks/use-billing-history' import { getStatusConfig, getPaymentMethodName, formatTimestamp, } from '../../lib/billing' interface BillingHistoryDialogProps { open: boolean onOpenChange: (open: boolean) => void } export function BillingHistoryDialog({ open, onOpenChange, }: BillingHistoryDialogProps) { const { t } = useTranslation() const { records, total, page, pageSize, keyword, loading, completing, isAdmin, handlePageChange, handlePageSizeChange, handleSearch, handleCompleteOrder, } = useBillingHistory() const [confirmTradeNo, setConfirmTradeNo] = useState(null) const { copyToClipboard, copiedText } = useCopyToClipboard({ notify: false }) const totalPages = Math.ceil(total / pageSize) const handleConfirmComplete = async () => { if (confirmTradeNo) { const success = await handleCompleteOrder(confirmTradeNo) if (success) { setConfirmTradeNo(null) } } } return ( <> {t('Billing History')} {t('View your topup transaction records and payment history')}
{/* Search and Filter Bar */}
handleSearch(e.target.value)} className='h-9 pl-10' />
{/* Records List */} {loading ? (
{Array.from({ length: 5 }).map((_, i) => (
))}
) : records.length === 0 ? (

{t('No billing records found')}

{keyword ? t('Try adjusting your search') : t('Your transaction history will appear here')}

) : (
{records.map((record) => { const statusConfig = getStatusConfig(record.status) return (
{/* Header Row */}
{record.trade_no} {isAdmin && record.user_id != null && ( )}
{formatTimestamp(record.create_time)}
{/* Details Grid */}
{getPaymentMethodName(record.payment_method, t)}
{formatCurrencyFromUSD(record.amount, { digitsLarge: 2, digitsSmall: 2, abbreviate: false, })}
{formatNumber(record.money)}
{/* Admin Actions */} {isAdmin && record.status === 'pending' && (
)}
) })}
)}
{/* Pagination */} {!loading && records.length > 0 && (
{t('Showing')} {(page - 1) * pageSize + 1}- {Math.min(page * pageSize, total)} {t('of')} {total}
{page} / {totalPages}
)}
{/* Confirm Complete Order Dialog */} !open && setConfirmTradeNo(null)} > {t('Complete Order')} {t( 'Are you sure you want to manually complete this order? The user will be credited with the corresponding quota.' )} {t('Cancel')} {completing ? t('Processing...') : t('Confirm')} ) }