'use client'; import { useState } from 'react'; import { Copy, Check, Trash2 } from 'lucide-react'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from '@/components/ui/table'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip'; import type { ApiKey } from './types'; interface ApiKeyTableProps { keys: ApiKey[]; onRevoke: (key: ApiKey) => void; isRevoking: boolean; } function formatDate(dateString: string | null): string { if (!dateString) return 'Never'; const date = new Date(dateString); const now = new Date(); const diffMs = now.getTime() - date.getTime(); const diffMins = Math.floor(diffMs / 60000); const diffHours = Math.floor(diffMs / 3600000); const diffDays = Math.floor(diffMs / 86400000); if (diffMins < 1) return 'Just now'; if (diffMins < 60) return `${diffMins} min ago`; if (diffHours < 24) return `${diffHours} hour${diffHours > 1 ? 's' : ''} ago`; if (diffDays < 7) return `${diffDays} day${diffDays > 1 ? 's' : ''} ago`; return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }); } export function ApiKeyTable({ keys, onRevoke, isRevoking }: ApiKeyTableProps) { const [copiedId, setCopiedId] = useState(null); const copyPrefix = (keyId: string, prefix: string) => { navigator.clipboard.writeText(prefix); setCopiedId(keyId); setTimeout(() => setCopiedId(null), 2000); }; if (keys.length === 0) { return (

No API keys yet. Generate your first key to get started.

); } return (
Name Key Created Last Used Uses Actions {keys.map((key) => ( {key.name} {key.key_prefix}... {formatDate(key.created_at)} {formatDate(key.last_used_at)} {key.usage_count}
{copiedId === key.id ? 'Copied!' : 'Copy prefix'} Revoke
))}
); }