import { Alert, Badge, Group, Paper, Progress, SimpleGrid, Stack, Table, Text, } from "@mantine/core"; import { AlertTriangle, Train } from "lucide-react"; import type { DeferredBookingRow, FleetAvailabilityRow } from "@/types/trainScheduling"; export function FleetAvailabilitySummary({ fleetAvailability = [], deferredBookings = [], }: { fleetAvailability?: FleetAvailabilityRow[]; deferredBookings?: DeferredBookingRow[]; }) { if (!fleetAvailability.length && !deferredBookings.length) return null; const totalNeeded = fleetAvailability.reduce((sum, row) => sum + row.needed, 0); const totalAvailable = fleetAvailability.reduce((sum, row) => sum + row.available, 0); const totalShortfall = fleetAvailability.reduce((sum, row) => sum + row.shortfall, 0); const fillRate = totalNeeded > 0 ? Math.round((Math.min(totalAvailable, totalNeeded) / totalNeeded) * 100) : 100; return ( Fleet wagon availability Plan is capped to available physical wagons by type 0 ? "yellow" : "green"}> {fillRate}% fleet coverage {totalNeeded > 0 ? ( {Math.min(totalAvailable, totalNeeded)} of {totalNeeded} wagon slots can be filled 0 ? "yellow" : "green"} /> ) : null} {fleetAvailability.length > 0 ? ( Wagon type Needed Available Shortfall {fleetAvailability.map((row) => ( {row.wagonTypeCode} {row.needed} {row.available} {row.shortfall > 0 ? ( {row.shortfall} ) : ( 0 )} ))}
) : null} {totalShortfall > 0 || deferredBookings.length > 0 ? ( }> Train will depart with available wagons only. {deferredBookings.length ? ` ${deferredBookings.length} booking(s) will wait for the next train.` : ""} ) : null} {deferredBookings.length > 0 ? ( {deferredBookings.map((booking) => ( {booking.reference} {booking.reason} Next train ))} ) : null}
); }