import { Badge } from '@/components/ui/badge'; import { Progress } from '@/components/ui/progress'; import { Star } from 'lucide-react'; export interface CriticalAlertData { requestId: string; requestNumber: string; title: string; priority: string; totalTATHours: number; originalTATHours: number; breachCount: number; currentLevel: number; totalLevels: number; } interface CriticalAlertCardProps { alert: CriticalAlertData; onNavigate?: (requestNumber: string) => void; testId?: string; } // Utility functions const calculateProgress = (alert: CriticalAlertData) => { if (!alert.originalTATHours || alert.originalTATHours === 0) return 0; const originalTAT = alert.originalTATHours; const remainingTAT = alert.totalTATHours; // If breached (negative remaining), show 100% if (remainingTAT <= 0) return 100; // Calculate elapsed time const elapsedTAT = originalTAT - remainingTAT; // Calculate percentage used const percentageUsed = (elapsedTAT / originalTAT) * 100; // Ensure it's between 0 and 100 return Math.min(100, Math.max(0, Math.round(percentageUsed))); }; const formatRemainingTime = (alert: CriticalAlertData) => { if (alert.totalTATHours === undefined || alert.totalTATHours === null) return 'N/A'; const hours = alert.totalTATHours; // If TAT is breached (negative or zero) if (hours <= 0) { const overdue = Math.abs(hours); if (overdue < 1) return `Breached`; if (overdue < 24) return `${Math.round(overdue)}h overdue`; return `${Math.round(overdue / 24)}d overdue`; } // If TAT is still remaining if (hours < 1) return `${Math.round(hours * 60)}min left`; if (hours < 24) return `${Math.round(hours)}h left`; return `${Math.round(hours / 24)}d left`; }; export function CriticalAlertCard({ alert, onNavigate, testId = 'critical-alert-card' }: CriticalAlertCardProps) { const progress = calculateProgress(alert); return (
{alert.requestNumber}
{alert.priority === 'express' && ({alert.title}