import { Badge, Group, Text, Tooltip } from "@mantine/core"; import { Boxes, Container, Weight } from "lucide-react"; import type { Freight } from "@edr/types"; /** * Compact human summary of a shipment request's requested cargo lines — the * quantities the customer asked for, before GL enters the real booking cargo. * Container contracts read "2 × 20ft, 1 × 40ft"; bulk reads "500 t" or * "300 items" depending on the contract's cargo configuration. */ export function summarizeRequestedCargo( lines?: Freight.RequestedShipmentLines | null, ): string { if (!lines) return "—"; const containers = (lines.containers ?? []).filter((c) => (c.quantity ?? 0) > 0); if (containers.length) { return containers.map((c) => `${c.quantity} × ${c.containerSize}`).join(", "); } if (lines.bulk) { if (lines.bulk.cargoWeightTons) return `${lines.bulk.cargoWeightTons} t`; if (lines.bulk.itemCount) return `${lines.bulk.itemCount} items`; } return "—"; } /** Renders the requested cargo as small badges (per container type, or bulk). */ export function RequestedCargoChips({ lines, size = "sm", }: { lines?: Freight.RequestedShipmentLines | null; size?: "xs" | "sm"; }) { const containers = (lines?.containers ?? []).filter((c) => (c.quantity ?? 0) > 0); if (containers.length) { return ( {containers.map((c, i) => { const flags: string[] = []; if ((c.hazardousQuantity ?? 0) > 0) flags.push(`${c.hazardousQuantity} hazardous`); if ((c.reeferQuantity ?? 0) > 0) flags.push(`${c.reeferQuantity} reefer`); const chip = ( } > {c.quantity} × {c.containerSize} ); return flags.length ? ( {chip} ) : ( {chip} ); })} ); } if (lines?.bulk && (lines.bulk.cargoWeightTons || lines.bulk.itemCount)) { const isWeight = Boolean(lines.bulk.cargoWeightTons); const value = lines.bulk.cargoWeightTons ?? lines.bulk.itemCount ?? 0; return ( : } > {value} {isWeight ? "t" : "items"} ); } return ( ); }