import React from 'react'; import { useTranslation } from 'react-i18next'; import { Database, Server, Cpu, Activity, Plug, HardDrive, BrainCircuit, AlertCircle, CheckCircle, XCircle, AlertTriangle, RefreshCw, } from 'lucide-react'; import { useSystemDashboard, useSystemAlerts } from '@/api/systemDashboard'; import { useAuthStore } from '@/store/authStore'; // ─── Status Badge ──────────────────────────────────────────────────────────── function StatusBadge({ status }: { status: string }) { const { t } = useTranslation(); const isUp = status === 'up' || status === 'healthy'; const isDegraded = status === 'degraded'; const isDown = status === 'down'; const config = isUp ? { icon: CheckCircle, color: 'text-success-600', bg: 'bg-success-50', label: t('systemDashboard.statusUp', 'OK') } : isDegraded ? { icon: AlertTriangle, color: 'text-warning-600', bg: 'bg-warning-50', label: t('systemDashboard.statusDegraded', 'Degraded') } : isDown ? { icon: XCircle, color: 'text-danger-600', bg: 'bg-danger-50', label: t('systemDashboard.statusDown', 'Down') } : { icon: AlertCircle, color: 'text-secondary-600', bg: 'bg-secondary-50', label: t('systemDashboard.statusUnknown', 'Unknown') }; const Icon = config.icon; return ( ); } // ─── Metric Card ───────────────────────────────────────────────────────────── interface MetricCardProps { title: string; icon: React.ReactNode; status?: string; children: React.ReactNode; } function MetricCard({ title, icon, status, children }: MetricCardProps) { return (
{icon}

{title}

{status && }
{children}
); } // ─── Stat Row ──────────────────────────────────────────────────────────────── function StatRow({ label, value }: { label: string; value: React.ReactNode }) { return (
{label} {value}
); } // ─── Alert Item ────────────────────────────────────────────────────────────── function AlertItem({ alert }: { alert: { severity: string; type: string; message: string } }) { const isCritical = alert.severity === 'critical'; const Icon = isCritical ? XCircle : AlertTriangle; const colorClass = isCritical ? 'text-danger-600 bg-danger-50 border-danger-200' : 'text-warning-600 bg-warning-50 border-warning-200'; return (
); } // ─── Main Page ──────────────────────────────────────────────────────────────── export function SystemDashboardPage() { const { t } = useTranslation(); const user = useAuthStore((state) => state.user); const isAdmin = user?.is_system_admin === true; const { data: dashboard, isLoading: dashboardLoading, error: dashboardError } = useSystemDashboard(); const { data: alertsData, isLoading: alertsLoading } = useSystemAlerts(); // Admin-only guard if (!isAdmin) { return (
); } if (dashboardLoading || alertsLoading) { return (
); } if (dashboardError || !dashboard) { return (
); } const alerts = alertsData?.alerts ?? []; const overallStatus = dashboard.overall_status; return (
{/* Header */}

{t('systemDashboard.title', 'System Dashboard')}

{t('systemDashboard.subtitle', 'Echtzeit-Systemüberwachung')} — {new Date(dashboard.timestamp).toLocaleString()}

{/* Alerts Section */} {alerts.length > 0 && (

{t('systemDashboard.activeAlerts', 'Aktive Alerts')} ({alerts.length})

{alerts.map((alert, idx) => ( ))}
)} {/* Metrics Grid */}
{/* Database */} {/* Redis */} {/* Worker */} {/* API Stats */} {/* Plugins */} {/* Storage */} {/* LLM Usage */}
); }