"use client"; import Link from "next/link"; import type { GameStructure, GameVehicle, Shipment, Vehicle } from "@/payload-types"; import { Item, ItemContent, ItemDescription, ItemHeader, ItemMedia, ItemTitle, } from "@/components/ui/item"; import { ShipmentProgressBar } from "@/components/frontend/logistics/ShipmentProgressBar"; import { ArrowRightIcon, ChevronRightIcon, TruckIcon } from "lucide-react"; interface ShipmentCardProps { shipment: Shipment; } const statusColors: Record = { pending: "bg-muted text-muted-foreground", dispatched: "bg-blue-500/20 text-blue-400", in_transit: "bg-amber-500/20 text-amber-400", arrived: "bg-green-500/20 text-green-400", completed: "bg-emerald-500/20 text-emerald-400", cancelled: "bg-muted text-muted-foreground", failed: "bg-red-500/20 text-red-400", stranded: "bg-red-500/20 text-red-400", }; export function ShipmentCard({ shipment }: ShipmentCardProps) { const origin = typeof shipment.origin === "object" && shipment.origin !== null ? (shipment.origin as GameStructure) : null; const destination = typeof shipment.destination === "object" && shipment.destination !== null ? (shipment.destination as GameStructure) : null; const vehicle = typeof shipment.transportVehicle === "object" && shipment.transportVehicle !== null ? (shipment.transportVehicle as GameVehicle & { type: Vehicle }) : null; const vehicleType = vehicle && typeof vehicle.type === "object" ? vehicle.type : null; const dispatchedAt = shipment.dispatchedAt ? new Date(shipment.dispatchedAt) : null; const estimatedArrival = shipment.estimatedArrival ? new Date(shipment.estimatedArrival) : null; const isActive = shipment.status === "dispatched" || shipment.status === "in_transit"; const cargoCount = shipment.cargo?.length ?? 0; const totalItems = shipment.cargo?.reduce((sum, c) => sum + (c.amount ?? 0), 0) ?? 0; return (
{shipment.name ?? `SHP-${shipment.id}`} {vehicleType?.name ?? "Unknown vehicle"}
{shipment.status === "in_transit" ? "In Transit" : shipment.status.charAt(0).toUpperCase() + shipment.status.slice(1)}
{origin?.name ?? `Structure #${shipment.origin}`} {destination?.name ?? `Structure #${shipment.destination}`}
{isActive && dispatchedAt && estimatedArrival && ( )}
{cargoCount} item type{cargoCount !== 1 ? "s" : ""} ({totalItems} total) {shipment.distance?.toFixed(1)} units ยท {shipment.fuelCost} fuel
{shipment.status === "completed" ? `Completed ${shipment.completedAt ? new Date(shipment.completedAt).toLocaleDateString() : ""}` : shipment.status === "cancelled" ? "Cancelled" : (shipment.failureReason ?? (isActive ? "In transit" : shipment.status))} View details
); }