import { Ban } from 'lucide-react'; import { Badge, Button, DataTable, Tooltip } from '../../../components/ui'; import { SCOPE_LABELS, type ApiKey } from '../../../modules/api-keys'; interface ApiKeyTableProps { data: ApiKey[]; isLoading: boolean; onRevoke: (key: ApiKey) => void; } function formatDate(value: string | null): string { if (!value) return '—'; const date = new Date(value); return date.toLocaleString('pt-BR', { dateStyle: 'short', timeStyle: 'short' }); } export function ApiKeyTable({ data, isLoading, onRevoke }: ApiKeyTableProps) { return ( data={data} isLoading={isLoading} emptyMessage="Nenhuma API Key emitida." rowKey="id" columns={[ { key: 'name', header: 'Nome', render: (k) => ( {k.name} ), }, { key: 'scopes', header: 'Escopos', render: (k) => (
{k.scopes.map((scope) => ( {SCOPE_LABELS[scope] ?? scope} ))}
), }, { key: 'lastFourChars', header: 'Chave', render: (k) => ( ••••••{k.lastFourChars} ), }, { key: 'isActive', header: 'Status', render: (k) => ( {k.isActive ? 'Ativa' : 'Revogada'} ), }, { key: 'expiresAt', header: 'Expiração', render: (k) => {formatDate(k.expiresAt)}, }, { key: 'lastUsedAt', header: 'Último uso', render: (k) => {formatDate(k.lastUsedAt)}, }, { key: 'actions', header: 'Ações', render: (k) => k.isActive ? ( ) : ( ), }, ]} /> ); }