import { CloudAccount } from '@/types/cloudAccount'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Checkbox } from '@/components/ui/checkbox'; import { MoreVertical, Trash, RefreshCw, Box, Power } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { Badge } from '@/components/ui/badge'; import { useTranslation } from 'react-i18next'; interface CloudAccountCardProps { account: CloudAccount; onRefresh: (id: string) => void; onDelete: (id: string) => void; onSwitch: (id: string) => void; isSelected?: boolean; onToggleSelection?: (id: string, selected: boolean) => void; isRefreshing?: boolean; isDeleting?: boolean; isSwitching?: boolean; } export function CloudAccountCard({ account, onRefresh, onDelete, onSwitch, isSelected = false, onToggleSelection, isRefreshing, isDeleting, isSwitching, }: CloudAccountCardProps) { const { t } = useTranslation(); // Helpers to get quota color const getQuotaColor = (percentage: number) => { if (percentage > 80) return 'text-green-500'; if (percentage > 20) return 'text-yellow-500'; return 'text-red-500'; }; const modelQuotas = Object.entries(account.quota?.models || {}); return ( {/* Selection Checkbox - Visible on hover or selected */} {onToggleSelection && (
onToggleSelection(account.id, checked as boolean)} className="h-5 w-5 border-2" />
)} {account.avatar_url ? ( {account.name ) : (
{account.name?.[0]?.toUpperCase() || 'A'}
)}
{account.name || t('cloud.card.unknown')} {account.email}
{t('cloud.card.actions')} onSwitch(account.id)} disabled={isSwitching}> {t('cloud.card.useAccount')} onRefresh(account.id)} disabled={isRefreshing}> {t('cloud.card.refresh')} onDelete(account.id)} className="text-destructive focus:text-destructive" disabled={isDeleting} > {t('cloud.card.delete')}
{account.provider.toUpperCase()} {account.is_active && ( {t('cloud.card.active')} )} {account.status === 'rate_limited' && ( {t('cloud.card.rateLimited')} )}
{account.is_active ? ( ) : ( )}
{modelQuotas.length > 0 ? ( modelQuotas.map(([modelName, info]) => (
{modelName.replace('models/', '')}
{info.percentage}% {t('cloud.card.left')}
)) ) : (
{t('cloud.card.noQuota')}
)}
{t('cloud.card.used')}{' '} {formatDistanceToNow(account.last_used * 1000, { addSuffix: true })}
); }