/** * Tab Content Components for Error Logs Monitor * OverviewTab, HeadersTab, BodyTab, RawTab */ import { ScrollArea } from '@/components/ui/scroll-area'; import { Info, Clock, Cpu, AlertTriangle } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { cn } from '@/lib/utils'; import { getErrorTypeLabel, formatQuotaResetDelay, formatQuotaResetTimestamp, type ParsedErrorLog, } from '@/lib/error-log-parser'; import { StatusBadge } from './ui-primitives'; /** Overview tab content */ export function OverviewTab({ parsed }: { parsed: ParsedErrorLog }) { const { t } = useTranslation(); const quotaResetDisplay = formatQuotaResetDelay(parsed.quotaResetDelay) || formatQuotaResetTimestamp(parsed.quotaResetTimestamp); const na = t('errorLogs.na'); return (
{/* Status row */}
{parsed.statusText} {getErrorTypeLabel(parsed.errorType)}
{/* Model info - prominent display */} {parsed.model && (
{t('errorLogs.modelLabel')} {parsed.model}
)} {/* Quota reset info for 429 errors */} {parsed.errorType === 'rate_limit' && quotaResetDisplay && (
{t('errorLogs.quotaResetsIn')} {quotaResetDisplay}
)} {/* Key metrics grid */}
{t('errorLogs.method')}
{parsed.method || na}
{t('errorLogs.provider')}
{parsed.provider || na}
{t('errorLogs.version')}
{parsed.version || na}
{t('errorLogs.endpoint')}
{parsed.endpoint || na}
{/* URL */}
{t('errorLogs.url')}
{parsed.url || na}
{/* Timestamp */}
{t('errorLogs.timestamp')}
{parsed.timestamp || na}
{/* Actionable suggestion based on error type */} {parsed.errorType !== 'unknown' && (
{parsed.errorType === 'rate_limit' ? ( ) : parsed.errorType === 'auth' ? ( ) : ( )}
{parsed.errorType === 'rate_limit' && (parsed.model ? t('errorLogs.rateLimitedMsg', { model: parsed.model }) : t('errorLogs.rateLimitedMsgNoModel'))} {parsed.errorType === 'auth' && t('errorLogs.authFailedMsg')} {parsed.errorType === 'not_found' && t('errorLogs.notFoundMsg')} {parsed.errorType === 'server' && t('errorLogs.serverErrorMsg')} {parsed.errorType === 'timeout' && t('errorLogs.timeoutMsg')}
)}
); } /** Headers tab content */ export function HeadersTab({ headers }: { headers: Record }) { const entries = Object.entries(headers); if (entries.length === 0) { return
No headers available
; } return (
{entries.map(([key, value]) => (
{key}: {value}
))}
); } /** JSON/Body tab content */ export function BodyTab({ content, label }: { content: string; label: string }) { const { t } = useTranslation(); if (!content || content.trim() === '') { const key = label === 'Request' ? 'errorLogs.noRequestBody' : 'errorLogs.noResponseBody'; return
{t(key)}
; } // Try to format as JSON let formatted = content; let isJson = false; try { const parsed = JSON.parse(content); formatted = JSON.stringify(parsed, null, 2); isJson = true; } catch { // Not JSON, use as-is } return (
        {formatted}
      
); } /** Raw tab content */ export function RawTab({ content }: { content: string }) { return (
        {content}
      
); }