import React, { useCallback, useEffect, useState } from 'react'; import { CheckCircle2, Clock, ShieldBan, XCircle } from 'lucide-react'; import { fetchSummary } from './api'; import { formatCount } from './format'; /** * At-a-glance counters above the logs. * * A table alone makes you read rows to work out whether anything is wrong. * These answer "is my site under attack right now?" in one glance. */ export default function SummaryCards({ refreshKey, onNavigate }) { const [data, setData] = useState(null); const [error, setError] = useState(null); const load = useCallback(async () => { try { setData(await fetchSummary()); setError(null); } catch (err) { setError(err.message); } }, []); useEffect(() => { load(); }, [load, refreshKey]); if (error || !data) return null; const tiles = [ { key: 'failed', label: 'Failed sign-ins', sub: 'last 24 hours', value: data.failed_24h, Icon: XCircle, tone: data.failed_24h > 0 ? 'warn' : 'ok', go: 'FailedLogins', }, { key: 'locked', label: 'Locked out now', sub: 'temporarily', value: data.locked_now, Icon: Clock, tone: data.locked_now > 0 ? 'warn' : 'ok', go: 'FailedLogins', }, { key: 'blocked', label: 'Blocked addresses', sub: 'currently denied', value: data.blocked_total, Icon: ShieldBan, tone: data.blocked_total > 0 ? 'danger' : 'ok', go: 'BlockUsers', }, { key: 'success', label: 'Successful sign-ins', sub: 'last 24 hours', value: data.successful_24h, Icon: CheckCircle2, tone: 'ok', go: 'SuccessfulLogins', }, ]; return (
{!data.protection_on && (
Brute-force protection is switched off. Failed sign-ins are still recorded, but no address will ever be locked out.{' '} Turn it on
)}
{tiles.map(({ key, label, sub, value, Icon, tone, go }) => ( ))}
{data.top_offender && (

Most active address in the last 24 hours:{' '} {data.top_offender.ip} — {data.top_offender.attempts}{' '} failed attempts, {data.top_offender.lockouts} lockouts.

)}
); }