import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { TrendingUp, Calendar, BarChart3 } from 'lucide-react'; import { UptimeData } from '@/types/service.types'; import { UptimeHistoryRenderer } from './UptimeHistoryRenderer'; interface OverallUptimeSectionProps { uptimeData: Record; } export const OverallUptimeSection = ({ uptimeData }: OverallUptimeSectionProps) => { const getOverallUptime = () => { const allHistories = Object.values(uptimeData); if (allHistories.length === 0) return 99.9; let totalRecords = 0; let upRecords = 0; allHistories.forEach(history => { totalRecords += history.length; upRecords += history.filter(record => record.status === 'up').length; }); if (totalRecords === 0) return 99.9; return Math.round((upRecords / totalRecords) * 100 * 100) / 100; }; const getUptimeTrend = () => { const uptime = getOverallUptime(); if (uptime >= 99.9) return 'excellent'; if (uptime >= 99.5) return 'good'; if (uptime >= 95) return 'fair'; return 'poor'; }; const getIncidentCount = () => { const allHistories = Object.values(uptimeData); let incidents = 0; allHistories.forEach(history => { let wasDown = false; history.forEach(record => { if (record.status === 'down' && !wasDown) { incidents++; wasDown = true; } else if (record.status === 'up') { wasDown = false; } }); }); return incidents; }; const getBadgeClassName = (trend: string) => { switch (trend) { case 'excellent': return 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200'; case 'good': return 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200'; case 'fair': return 'bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200'; default: return 'bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200'; } }; const getTrendText = (trend: string) => { switch (trend) { case 'excellent': return 'Excellent'; case 'good': return 'Good'; case 'fair': return 'Fair'; default: return 'Needs Improvement'; } }; const getStatusMessage = (uptime: number) => { if (uptime >= 99.9) { return "All systems are performing excellently with minimal downtime."; } else if (uptime >= 99.5) { return "Systems are performing well with occasional minor issues."; } else if (uptime >= 95) { return "We're working to improve system reliability and reduce incidents."; } else { return "We apologize for recent service disruptions and are actively working on improvements."; } }; const overallUptime = getOverallUptime(); const trend = getUptimeTrend(); const incidentCount = getIncidentCount(); return ( Performance Metrics (Last 90 Days)

Historical performance and reliability statistics

Overall Uptime
{getTrendText(trend)}
{overallUptime}%
Target: 99.9%
Incidents
{incidentCount}
Last 90 days
Avg Response
100ms
Response time

Uptime History

Operational
Degraded
Down
{Object.keys(uptimeData).length > 0 ? ( ) : (
{Array.from({ length: 90 }, (_, i) => (
))}
)}
90 days ago Today
{getStatusMessage(overallUptime)}
); };