import type { DhlTrackingResult, DhlTrackingStatus } from "@/lib/dhl-tracking"; import type { Locale } from "@/i18n/config"; import { formatDate, formatDateTime } from "@/lib/format"; export interface ShipmentTrackingHistoryLabels { heading: string; ariaLabel: string; estimatedDelivery: (date: string) => string; notYetScanned: string; unavailable: string; dataSource: string; statuses: Record; } const STATUS_DOT: Record = { "pre-transit": "bg-ink/30", transit: "bg-honey-dark", delivered: "bg-forest", failure: "bg-red-500", unknown: "bg-ink/30", }; const STATUS_TEXT: Record = { "pre-transit": "text-ink/70", transit: "text-honey-dark", delivered: "text-forest", failure: "text-red-700", unknown: "text-ink/70", }; /** * Zeigt den DHL-Sendungsverlauf im eigenen Layout, damit Kundschaft nicht * auf dhl.de wechseln muss. Rendert fuer "disabled" nichts — solange kein * Tracking-Key hinterlegt ist, bleibt die Seite exakt wie bisher (Nummer + * Link). Alle Texte aus der DHL-Antwort landen ausschliesslich als * React-Textknoten im DOM, nie als HTML. */ export function ShipmentTrackingHistory({ result, locale, labels, }: { result: DhlTrackingResult; locale: Locale; labels: ShipmentTrackingHistoryLabels; }) { if (result.kind === "disabled") return null; if (result.kind !== "ok") { return (

{labels.heading}

{result.kind === "not-found" ? labels.notYetScanned : labels.unavailable}

); } const { info } = result; return (

{labels.heading}

{labels.statuses[info.status]}
{info.estimatedDelivery && info.status !== "delivered" ? (

{labels.estimatedDelivery(formatDate(info.estimatedDelivery, locale))}

) : null} {info.events.length > 0 ? (
    {info.events.map((event, i) => (
  1. {i < info.events.length - 1 ? (
  2. ))}
) : (

{labels.notYetScanned}

)}

{labels.dataSource}

); }