/*
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 (
<>
{/* 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')}
>
)
}