import type { DispatchTotalsSnapshot } from "@lumo/widgets/catalog/logistics/dispatched-today";
type Consignment = {
id: string;
destination: string;
state: "queued" | "dispatched" | "delayed";
reason?: string;
nextDeparture?: string;
};
export function toDispatchTotals(
shipments: readonly Consignment[],
period: string,
target: number | null,
cutoff: string,
expectedByNow?: number,
): DispatchTotalsSnapshot {
return {
period,
target,
cutoff,
expectedByNow,
dispatched: shipments.filter(item => item.state === "dispatched").length,
delayed: shipments
.filter(item => item.state === "delayed")
.map(({ id, destination, reason, nextDeparture }) => ({ id, destination, reason, nextDeparture })),
};
}