'use client'; import { useState } from 'react'; import { SystemConfig } from '@/lib/types/settings'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'; import { Switch } from '@/components/ui/switch'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'; import { updateSystemSetting, purgeSystemCache } from '@/lib/actions/settings'; import { toast } from 'sonner'; import { Server, CreditCard, Radio, Trash2, AlertTriangle, Activity } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; interface SystemHealthProps { config: SystemConfig; onUpdate: (data: SystemConfig) => void; } export function SystemHealthTab({ config, onUpdate }: SystemHealthProps) { const [loading, setLoading] = useState(false); const [state, setState] = useState(config); const [purgeLoading, setPurgeLoading] = useState(false); const handleSave = async () => { setLoading(true); try { const res = await updateSystemSetting('system', state); if (res.success && res.updatedSettings.system) { toast.success('System configuration updated'); onUpdate(res.updatedSettings.system); } } catch (error) { toast.error('Failed to update system config'); } finally { setLoading(false); } }; const handlePurgeCache = async () => { setPurgeLoading(true); try { const res = await purgeSystemCache(); if (res.success) { toast.success('Cache purged successfully', { description: 'Changes are propagating to edge locations.' }); } } catch (error) { toast.error('Failed to purge cache'); } finally { setPurgeLoading(false); } }; return (
Uptime: 99.99%
Last Purged: {state.cache.lastPurgedAt ? new Date(state.cache.lastPurgedAt).toLocaleTimeString() : 'Never'}
Latency: 24ms
{false ? Active - App Offline : Inactive - App Live}
Items cached: ~14.2k