import { formatDateTime } from "@/lib/format-date";
/**
* Horizontal stepper showing the order's progression:
* Placed → Ready → Picked up.
*
* Derived from the legacy `orders` row:
* - Placed: always set (created_at)
* - Ready: orders.status = 'confirmed' (no dedicated timestamp in the
* legacy schema; we surface "—" rather than fabricating one)
* - Picked up: orders.pickup_complete = true → pickup_completed_at
*
* Cancelled orders get a single "Cancelled" pill instead of the stepper
* — the timeline doesn't make sense for a voided order.
*/
export type FulfillmentStatus = "placed" | "ready" | "picked-up" | "cancelled";
interface FulfillmentTimelineProps {
status: FulfillmentStatus;
placedAt: string;
pickedUpAt: string | null;
}
const STEPS: { key: FulfillmentStatus; label: string }[] = [
{ key: "placed", label: "Placed" },
{ key: "ready", label: "Ready" },
{ key: "picked-up", label: "Picked up" },
];
function stepState(
step: FulfillmentStatus,
current: FulfillmentStatus,
): "done" | "current" | "upcoming" {
const order = STEPS.findIndex((s) => s.key === step);
const currentIdx = STEPS.findIndex((s) => s.key === current);
if (currentIdx === -1) return "upcoming";
if (order < currentIdx) return "done";
if (order === currentIdx) return "current";
return "upcoming";
}
export function FulfillmentTimeline({
status,
placedAt,
pickedUpAt,
}: FulfillmentTimelineProps) {
if (status === "cancelled") {
return (
STATUS
Cancelled
);
}
return (
FULFILLMENT
{STEPS.map((step, i) => {
const state = stepState(step.key, status);
const isLast = i === STEPS.length - 1;
// Pick the right timestamp to display. The "Ready" step has no
// dedicated column in the legacy schema, so we show "—" — the
// user can read the mark-ready time from the audit log.
const ts =
step.key === "placed"
? placedAt
: step.key === "picked-up"
? pickedUpAt
: null;
const dotBg =
state === "done"
? "var(--color-accent)"
: state === "current"
? "var(--color-accent-2)"
: "var(--color-surface-3)";
const labelColor =
state === "upcoming" ? "var(--color-text-faint)" : "var(--color-text)";
return (