import React from "react"; import { Card, CardContent, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card.tsx"; import { Button } from "@/components/ui/button.tsx"; import { Badge } from "@/components/ui/badge.tsx"; import { X, ExternalLink, AlertTriangle, Info, CheckCircle, AlertCircle, } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { TermixAlert } from "../../../types/index.js"; interface AlertCardProps { alert: TermixAlert; onDismiss: (alertId: string) => void; onClose: () => void; } const getAlertIcon = (type?: string) => { switch (type) { case "warning": return ; case "error": return ; case "success": return ; case "info": default: return ; } }; const getPriorityBadgeVariant = (priority?: string) => { switch (priority) { case "critical": return "destructive"; case "high": return "destructive"; case "medium": return "secondary"; case "low": default: return "outline"; } }; const getTypeBadgeVariant = (type?: string) => { switch (type) { case "warning": return "secondary"; case "error": return "destructive"; case "success": return "default"; case "info": default: return "outline"; } }; export function HomepageAlertCard({ alert, onDismiss, onClose, }: AlertCardProps): React.ReactElement { const { t } = useTranslation(); if (!alert) { return null; } const handleDismiss = () => { onDismiss(alert.id); onClose(); }; const formatExpiryDate = (expiryString: string) => { const expiryDate = new Date(expiryString); const now = new Date(); const diffTime = expiryDate.getTime() - now.getTime(); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); if (diffDays < 0) return t("common.expired"); if (diffDays === 0) return t("common.expiresToday"); if (diffDays === 1) return t("common.expiresTomorrow"); return t("common.expiresInDays", { days: diffDays }); }; return (
{getAlertIcon(alert.type)} {alert.title}
{alert.priority && ( {alert.priority.toUpperCase()} )} {alert.type && ( {alert.type} )} {formatExpiryDate(alert.expiresAt)}

{alert.message}

{alert.actionUrl && alert.actionText && ( )}
); }