"use client"; import { cn } from "@/lib/utils"; import { Bell, BellOff, Check, AlertTriangle, Info, XCircle } from "lucide-react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { ScrollArea } from "@/components/ui/scroll-area"; import { ChainIcon } from "./ChainIcon"; import type { Alert } from "@/lib/mock/cryptoMockData"; interface AlertsPanelProps { alerts: Alert[]; onAlertClick?: (alert: Alert) => void; onMarkAsRead?: (alertId: string) => void; onMarkAllAsRead?: () => void; onDismiss?: (alertId: string) => void; className?: string; } function formatTimeAgo(date: Date): string { const seconds = Math.floor((Date.now() - date.getTime()) / 1000); if (seconds < 60) return "just now"; const minutes = Math.floor(seconds / 60); if (minutes < 60) return `${minutes}m ago`; const hours = Math.floor(minutes / 60); if (hours < 24) return `${hours}h ago`; const days = Math.floor(hours / 24); return `${days}d ago`; } function getSeverityConfig(severity: Alert["severity"]) { switch (severity) { case "critical": return { icon: XCircle, color: "text-red-500", bg: "bg-red-500/10", border: "border-red-500/20", }; case "warning": return { icon: AlertTriangle, color: "text-yellow-500", bg: "bg-yellow-500/10", border: "border-yellow-500/20", }; default: return { icon: Info, color: "text-blue-500", bg: "bg-blue-500/10", border: "border-blue-500/20", }; } } function AlertItem({ alert, onClick, onMarkAsRead, onDismiss, }: { alert: Alert; onClick?: () => void; onMarkAsRead?: () => void; onDismiss?: () => void; }) { const config = getSeverityConfig(alert.severity); const Icon = config.icon; return (
{alert.tokenSymbol} {!alert.isRead && ( NEW )}

{alert.message}

{formatTimeAgo(alert.timestamp)}

{!alert.isRead && ( )}
); } export function AlertsPanel({ alerts, onAlertClick, onMarkAsRead, onMarkAllAsRead, onDismiss, className, }: AlertsPanelProps) { const unreadCount = alerts.filter((a) => !a.isRead).length; return (
Alerts {unreadCount > 0 && ( {unreadCount} )} {unreadCount > 0 && ( )}
{alerts.length === 0 ? (

No alerts yet

Configure alerts on your watchlist tokens

) : (
{alerts.map((alert) => ( onAlertClick?.(alert)} onMarkAsRead={() => onMarkAsRead?.(alert.id)} onDismiss={() => onDismiss?.(alert.id)} /> ))}
)}
); }