'use client'; import { AlertTriangle, Bell, Check, ExternalLink, Info, ShieldAlert, X } from 'lucide-react'; import { useRouter } from 'next/navigation'; import { formatDistanceToNow } from 'date-fns'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import type { AlertRow } from './types'; import { useAlertActions } from './use-alerts'; interface AlertCardProps { alert: AlertRow; /** Hide the side action buttons in compact contexts (e.g. resolved/dismissed history). */ readOnly?: boolean; } const SEVERITY_STYLES: Record = { info: { stripe: 'bg-[hsl(var(--chart-1))]', icon: Info }, warning: { stripe: 'bg-amber-500', icon: AlertTriangle }, critical: { stripe: 'bg-destructive', icon: ShieldAlert }, }; export function AlertCard({ alert, readOnly = false }: AlertCardProps) { const router = useRouter(); const { acknowledge, dismiss } = useAlertActions(); const sev = SEVERITY_STYLES[alert.severity] ?? SEVERITY_STYLES.info!; const Icon = sev.icon; const acknowledged = Boolean(alert.acknowledgedAt); const fired = formatDistanceToNow(new Date(alert.firedAt), { addSuffix: true }); return (

{alert.title}

{acknowledged ? ( ack ) : null}
{alert.body ? (

{alert.body}

) : null}
{fired} ยท {alert.ruleId}
{!readOnly ? (
{!acknowledged ? ( ) : null} {alert.link ? ( ) : null}
) : null}
); } export function AlertCardEmpty() { return (

All clear

No active alerts right now.

); }