# AI order status

> In-chat live delivery tracker with pulsing status badge, three-stage route progress indicator, expandable courier message form, and replay.

- Kind: block · Category: AI · Interactivity: script
- Install: `npx shadcn@latest add @haze/ai-order-status`
- File: `src/components/haze/blocks/ai-order-status.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/utils
- Docs page: https://hazeui.com/blocks/ai-order-status

## Use when
- Answering an order status question inside a support or shopping assistant thread with live ETA telemetry
- Showing courier transit stages alongside a quick drop-off message form without leaving the conversation
- Demonstrating real-time arrival progression with an interactive Simulate arrival and Replay toggle

## Avoid when
- Completing the initial purchase or modifying item quantities before ordering; use ai-checkout
- Displaying a static multi-day shipping history log with timestamps; use timeline instead

## Alternatives
- [ai-checkout](https://hazeui.com/blocks/ai-checkout.md)
- [timeline](https://hazeui.com/ui/timeline.md)
- [progress](https://hazeui.com/ui/progress.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-ai-order-status" | no | Unique prefix for section heading and courier message form IDs. |
| heading | `string` | "Live order status" | no | Screen-reader section heading for landmark navigation. |
| userPrompt | `string` | "Where are my flowers?" | no | User message asking for the delivery update. |
| assistantReply | `string` | "They're on the way with Leo. I'll keep this updated." | no | Assistant reply introducing the live delivery card. |
| merchant | `string` | "Fern & Petal" | no | Store or restaurant name in the card header. |
| orderNumber | `string` | "4821" | no | Order reference shown next to the merchant name. |
| etaText | `string` | "Arriving around 2:14 pm" | no | Arrival window text displayed above the ETA minutes. |
| etaMinutes | `number` | 11 | no | Estimated minutes remaining before delivery. |
| courierName | `string` | "Leo" | no | Assigned courier display name. |
| courierInitial | `string` | "L" | no | Single-letter avatar initial for the courier badge. |
| courierVehicle | `string` | "Electric bike" | no | Courier transport description. |
| quickReplies | `string[]` | 2 quick drop-off chips | no | Suggested one-click instructions inside the courier message form. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- The delivery route bar exposes role="progressbar" with live aria-valuenow updates as the courier moves from 62% transit to 100% delivered.
- Message courier uses aria-expanded and aria-controls to manage the expandable drop-off note form, and arrival transitions honor prefers-reduced-motion.
- Key Tab: Move between Message courier, quick-reply chips, the message input, and Simulate arrival / Replay
- Key Enter / Space: Expand the courier message form, send a drop-off note, or trigger arrival simulation

## Agent prompts

### Install and use

Install the Haze UI block "AI order status" with `npx shadcn@latest add @haze/ai-order-status`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AiOrderStatus from "@/components/haze/blocks/ai-order-status.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/ai-order-status.md

### Customize with real content

Adapt the Haze ai-order-status block for our product. Replace the demo values of these props with our real content: id, heading, userPrompt, assistantReply, merchant, orderNumber, etaText, etaMinutes, courierName, courierInitial, courierVehicle, quickReplies, class. Keep the layout, the heading level rules and these accessibility details: The delivery route bar exposes role="progressbar" with live aria-valuenow updates as the courier moves from 62% transit to 100% delivered. Message courier uses aria-expanded and aria-controls to manage the expandable drop-off note form, and arrival transitions honor prefers-reduced-motion. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using ai-order-status, check it fits: use it when answering an order status question inside a support or shopping assistant thread with live eta telemetry; showing courier transit stages alongside a quick drop-off message form without leaving the conversation; demonstrating real-time arrival progression with an interactive simulate arrival and replay toggle. Avoid it when completing the initial purchase or modifying item quantities before ordering; use ai-checkout; displaying a static multi-day shipping history log with timestamps; use timeline instead. Alternatives: @haze/ai-checkout, @haze/timeline, @haze/progress.

## Example requests that should lead here
- Build an AI in-chat order status card with a pulsing Live badge, 3-stage courier progress bar, expandable Message courier form, and Simulate arrival
- Add a bouquet delivery tracking bubble in an assistant chat that switches from brand transit styling to success styling upon delivery

## Source

```astro
---
import { MessageCircle, Send } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";

interface Props {
  id?: string;
  heading?: string;
  userPrompt?: string;
  assistantReply?: string;
  merchant?: string;
  orderNumber?: string;
  etaText?: string;
  etaMinutes?: number;
  courierName?: string;
  courierInitial?: string;
  courierVehicle?: string;
  quickReplies?: string[];
  class?: string;
}

const {
  id = "haze-ai-order-status",
  heading = "Live order status",
  userPrompt = "Where are my flowers?",
  assistantReply = "They're on the way with Leo. I'll keep this updated.",
  merchant = "Fern & Petal",
  orderNumber = "4821",
  etaText = "Arriving around 2:14 pm",
  etaMinutes = 11,
  courierName = "Leo",
  courierInitial = "L",
  courierVehicle = "Electric bike",
  quickReplies = ["Leave at front porch", "Ring buzzer 4B"],
  class: className,
} = Astro.props;

const parkDots: Array<{ cx: number; cy: number }> = [];
for (let row = 0; row < 5; row++) {
  for (let col = 0; col < 10; col++) {
    parkDots.push({ cx: 120 + col * 8, cy: 76 + row * 7 });
  }
}
---

<section
  aria-labelledby={`${id}-title`}
  data-haze-ai-order-status
  data-initial-eta={etaText}
  data-initial-minutes={String(etaMinutes)}
  data-courier-name={courierName}
  class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}
>
  <h2 id={`${id}-title`} class="sr-only">{heading}</h2>

  <div class="mx-auto max-w-md space-y-3.5">
    <div class="flex justify-end">
      <p class="max-w-[85%] rounded-2xl bg-muted px-4 py-2.5 text-sm/5 text-foreground">
        {userPrompt}
      </p>
    </div>

    <p class="text-[0.9375rem]/6 text-pretty text-foreground">
      {assistantReply}
    </p>

    <div class="overflow-hidden rounded-2xl border border-border bg-muted/40 p-1.5">
      <div class="flex items-center justify-between gap-2 px-3 py-2 text-xs/5">
        <h3 class="truncate text-muted-foreground">
          <span class="font-semibold text-foreground">{merchant}</span> · Order {orderNumber}
        </h3>
        <button
          type="button"
          data-ord-sim
          class="inline-flex min-h-7 shrink-0 cursor-pointer items-center gap-1.5 rounded-full px-2 text-xs/5 font-medium text-muted-foreground transition-colors duration-150 ease-snappy hover:bg-accent hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
        >
          <span data-ord-dot-wrap class="relative flex size-2" aria-hidden="true">
            <span data-ord-ping class="absolute inline-flex size-full rounded-full bg-foreground opacity-75 animate-ping"></span>
            <span data-ord-dot class="relative inline-flex size-2 rounded-full bg-foreground"></span>
          </span>
          <span data-ord-badge-label>Live</span>
        </button>
      </div>

      <div class="overflow-hidden rounded-xl border border-border bg-card">
        <div class="flex items-end justify-between gap-3 px-4 pt-4 pb-3">
          <div class="min-w-0">
            <p data-ord-eta class="truncate text-xs/5 text-muted-foreground">{etaText}</p>
            <p class="mt-0.5 flex items-baseline gap-1.5 tabular-nums">
              <span data-ord-minutes class="text-2xl/7 font-bold tracking-tight text-foreground">{etaMinutes}</span>
              <span data-ord-unit class="text-sm/5 text-muted-foreground">min</span>
            </p>
          </div>

          <div
            role="progressbar"
            aria-label="Delivery route progress"
            aria-valuemin="0"
            aria-valuemax="100"
            aria-valuenow="56"
            data-ord-progress
            class="flex shrink-0 items-center gap-1.5 pb-1.5"
          >
            <span data-ord-seg="0" class="h-1 w-6 rounded-full bg-foreground transition-colors duration-300 ease-snappy"></span>
            <span data-ord-seg="1" class="h-1 w-6 rounded-full bg-foreground transition-colors duration-300 ease-snappy"></span>
            <span data-ord-seg="2" class="h-1 w-6 rounded-full bg-muted transition-colors duration-300 ease-snappy"></span>
          </div>
        </div>

        <div class="relative border-y border-border bg-muted/20">
          <svg viewBox="0 0 360 112" class="block h-28 w-full" fill="none" aria-hidden="true">
            <path d="M 0 28 L 164 20 M 0 64 L 360 64 M 112 10 L 112 112 M 234 10 L 274 112" class="stroke-border" stroke-width="5" stroke-opacity="0.55" />
            <path d="M 0 92 L 360 92 M 58 0 L 58 112" class="stroke-border" stroke-width="2" stroke-opacity="0.4" />

            {
              parkDots.map((pt) => (
                <circle cx={pt.cx} cy={pt.cy} r="1.15" class="fill-muted-foreground/40" />
              ))
            }

            <path
              data-ord-route-base
              d="M 46 80 C 96 80, 118 44, 174 44 C 222 44, 240 78, 276 62 C 294 54, 302 44, 314 38"
              class="stroke-border-strong"
              stroke-width="2.5"
              stroke-linecap="round"
              stroke-dasharray="4 5"
            />

            <path
              data-ord-route-active
              d="M 46 80 C 96 80, 118 44, 174 44 C 222 44, 240 78, 276 62 C 294 54, 302 44, 314 38"
              pathLength="100"
              stroke-dasharray="100"
              stroke-dashoffset="48"
              class="stroke-foreground transition-[stroke] duration-300 ease-snappy"
              stroke-width="3"
              stroke-linecap="round"
            />

            <g transform="translate(46 80)">
              <circle r="13" class="fill-card stroke-border-strong" stroke-width="1.5" />
              <g class="text-muted-foreground" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
                <path d="M -5 -1 L -4 -5 H 4 L 5 -1" />
                <path d="M -4 -1 V 4.5 H 4 V -1" />
                <path d="M -1.5 4.5 V 1.5 H 1.5 V 4.5" />
              </g>
            </g>

            <g transform="translate(314 38)">
              <circle r="13" class="fill-card stroke-border-strong" stroke-width="1.5" />
              <g class="text-muted-foreground" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round">
                <path d="M -5 0 L 0 -4.5 L 5 0" />
                <path d="M -3.5 -1 V 4.5 H 3.5 V -1" />
              </g>
            </g>

            <g data-ord-courier transform="translate(174 44)">
              <circle data-ord-halo r="19" class="fill-brand/20 transition-[fill] duration-300 ease-snappy" />
              <circle data-ord-pin r="13" class="fill-brand transition-[fill] duration-300 ease-snappy" />
              <g data-ord-bike-svg class="text-brand-foreground" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
                <circle cx="-4" cy="3" r="2.2" />
                <circle cx="4" cy="3" r="2.2" />
                <path d="M -4 3 L -1 -2 H 2.5 L 4 3" />
                <path d="M -1 -2 L 0.5 3 H -4" />
                <path d="M 1.5 -4 H 3.8" />
              </g>
              <g data-ord-check-svg class="hidden text-success-foreground" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                <path d="M -4 0.5 L -1 3.5 L 4.5 -3" />
              </g>
            </g>
          </svg>
        </div>

        <div class="flex flex-wrap items-center justify-between gap-3 px-4 py-3">
          <div class="flex min-w-0 items-center gap-2.5">
            <span
              class="inline-flex size-9 shrink-0 items-center justify-center rounded-full bg-muted text-xs font-semibold text-foreground"
              aria-hidden="true"
            >
              {courierInitial}
            </span>
            <div class="min-w-0">
              <p class="truncate text-sm/5 font-semibold text-foreground">{courierName}</p>
              <p class="truncate text-xs/4 text-muted-foreground">{courierVehicle}</p>
            </div>
          </div>

          <button
            type="button"
            data-ord-msg-toggle
            aria-expanded="false"
            aria-controls={`${id}-msg-form`}
            class="inline-flex h-9 shrink-0 cursor-pointer items-center gap-1.5 rounded-full border border-frame bg-field px-4 text-xs/5 font-medium text-foreground transition-colors duration-150 ease-snappy hover:border-frame-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97]"
          >
            <MessageCircle class="size-3.5 text-muted-foreground" aria-hidden="true" />
            Message
          </button>
        </div>

        <form id={`${id}-msg-form`} data-ord-msg-form hidden class="space-y-2.5 border-t border-border bg-muted/20 px-4 py-3">
          <div class="flex flex-wrap gap-1.5">
            {
              quickReplies.map((reply) => (
                <button
                  type="button"
                  data-ord-quick={reply}
                  class="inline-flex min-h-7 cursor-pointer items-center rounded-full border border-frame bg-field px-2.5 text-xs/4 text-muted-foreground transition-colors duration-150 ease-snappy hover:border-frame-strong hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
                >
                  {reply}
                </button>
              ))
            }
          </div>
          <div class="flex flex-wrap items-center gap-2">
            <label for={`${id}-courier-note`} class="sr-only">Message for {courierName}</label>
            <input
              id={`${id}-courier-note`}
              type="text"
              data-ord-msg-input
              placeholder={`Send drop-off note to ${courierName}…`}
              class="min-h-8 min-w-0 flex-1 rounded-full border border-frame-input bg-field px-3 py-1 text-xs/5 text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden"
            />
            <button
              type="submit"
              class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-full bg-primary px-3.5 text-xs/5 font-semibold text-primary-foreground transition-[opacity,scale] duration-150 ease-snappy hover:opacity-92 focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97]"
            >
              <Send class="size-3" aria-hidden="true" />
              Send
            </button>
          </div>
        </form>

        <p data-ord-sent-note hidden class="border-t border-border bg-muted/20 px-4 py-2.5 text-xs/5 text-foreground"></p>
      </div>
    </div>

    <p data-ord-status role="status" class="sr-only"></p>
  </div>
</section>

<script>
  function initAiOrderStatus() {
    document.querySelectorAll<HTMLElement>("[data-haze-ai-order-status]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");

      const initialEta = root.dataset.initialEta ?? "Arriving around 2:14 pm";
      const initialMinutes = Number(root.dataset.initialMinutes ?? 11);
      const courierName = root.dataset.courierName ?? "Leo";

      const etaEl = root.querySelector<HTMLElement>("[data-ord-eta]");
      const minutesEl = root.querySelector<HTMLElement>("[data-ord-minutes]");
      const unitEl = root.querySelector<HTMLElement>("[data-ord-unit]");
      const badgeLabel = root.querySelector<HTMLElement>("[data-ord-badge-label]");
      const ping = root.querySelector<HTMLElement>("[data-ord-ping]");
      const dot = root.querySelector<HTMLElement>("[data-ord-dot]");
      const progress = root.querySelector<HTMLElement>("[data-ord-progress]");
      const segs = [
        root.querySelector<HTMLElement>("[data-ord-seg='0']"),
        root.querySelector<HTMLElement>("[data-ord-seg='1']"),
        root.querySelector<HTMLElement>("[data-ord-seg='2']"),
      ];
      const routePath = root.querySelector<SVGPathElement>("[data-ord-route-active]");
      const courierGroup = root.querySelector<SVGGElement>("[data-ord-courier]");
      const halo = root.querySelector<SVGCircleElement>("[data-ord-halo]");
      const pin = root.querySelector<SVGCircleElement>("[data-ord-pin]");
      const bikeSvg = root.querySelector<SVGGElement>("[data-ord-bike-svg]");
      const checkSvg = root.querySelector<SVGGElement>("[data-ord-check-svg]");
      const msgToggle = root.querySelector<HTMLButtonElement>("[data-ord-msg-toggle]");
      const msgForm = root.querySelector<HTMLFormElement>("[data-ord-msg-form]");
      const msgInput = root.querySelector<HTMLInputElement>("[data-ord-msg-input]");
      const sentNote = root.querySelector<HTMLElement>("[data-ord-sent-note]");
      const simBtn = root.querySelector<HTMLButtonElement>("[data-ord-sim]");
      const status = root.querySelector<HTMLElement>("[data-ord-status]");

      let delivered = false;
      let currentPct = 52;
      let rafId: number | undefined;
      let timerId: number | undefined;

      const clearTimers = () => {
        if (rafId !== undefined) {
          window.cancelAnimationFrame(rafId);
          rafId = undefined;
        }
        if (timerId !== undefined) {
          window.clearTimeout(timerId);
          timerId = undefined;
        }
      };

      const positionCourier = (pct: number) => {
        const clamped = Math.max(0, Math.min(100, pct));
        currentPct = clamped;
        if (routePath) {
          routePath.style.strokeDashoffset = String(100 - clamped);
          if (courierGroup && typeof routePath.getTotalLength === "function") {
            const len = routePath.getTotalLength();
            const pt = routePath.getPointAtLength((clamped / 100) * len);
            courierGroup.setAttribute("transform", `translate(${pt.x.toFixed(1)} ${pt.y.toFixed(1)})`);
          }
        }
        if (progress) progress.setAttribute("aria-valuenow", String(Math.round(clamped)));
      };

      const setVisualState = (isDone: boolean, etaCopy: string, minsCopy: string, unitCopy: string) => {
        if (etaEl) etaEl.textContent = etaCopy;
        if (minutesEl) minutesEl.textContent = minsCopy;
        if (unitEl) unitEl.textContent = unitCopy;
        if (badgeLabel) badgeLabel.textContent = isDone ? "Delivered · Replay" : "Live";
        if (ping) ping.hidden = isDone;
        if (dot) {
          dot.classList.toggle("bg-foreground", !isDone);
          dot.classList.toggle("bg-success", isDone);
        }

        segs.forEach((seg, idx) => {
          if (!seg) return;
          seg.classList.toggle("bg-foreground", !isDone && idx < 2);
          seg.classList.toggle("bg-muted", !isDone && idx === 2);
          seg.classList.toggle("bg-success", isDone);
        });

        routePath?.classList.toggle("stroke-foreground", !isDone);
        routePath?.classList.toggle("stroke-success", isDone);
        halo?.classList.toggle("fill-brand/20", !isDone);
        halo?.classList.toggle("fill-success/20", isDone);
        pin?.classList.toggle("fill-brand", !isDone);
        pin?.classList.toggle("fill-success", isDone);
        bikeSvg?.classList.toggle("hidden", isDone);
        checkSvg?.classList.toggle("hidden", !isDone);
      };

      const animateTo = (targetPct: number, durationMs: number, onDone?: () => void) => {
        const startPct = currentPct;
        const start = performance.now();
        const step = (now: number) => {
          const t = Math.min(1, (now - start) / durationMs);
          const eased = 1 - Math.pow(1 - t, 3);
          positionCourier(startPct + (targetPct - startPct) * eased);
          if (t < 1) {
            rafId = window.requestAnimationFrame(step);
          } else {
            rafId = undefined;
            onDone?.();
          }
        };
        rafId = window.requestAnimationFrame(step);
      };

      positionCourier(52);

      simBtn?.addEventListener("click", () => {
        clearTimers();
        if (delivered) {
          delivered = false;
          positionCourier(52);
          setVisualState(false, initialEta, String(initialMinutes), "min");
          if (status) status.textContent = "Delivery replay reset to live transit.";
          return;
        }

        const reduced = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
        if (reduced) {
          delivered = true;
          positionCourier(100);
          setVisualState(true, "Delivered at 2:14 pm · Front porch", "Arrived", "");
          if (status) status.textContent = `Order delivered by ${courierName} at 2:14 pm.`;
          return;
        }

        if (simBtn) simBtn.disabled = true;
        if (minutesEl) minutesEl.textContent = "3";
        if (status) status.textContent = `${courierName} is 3 minutes away.`;

        animateTo(82, 550, () => {
          timerId = window.setTimeout(() => {
            animateTo(100, 500, () => {
              delivered = true;
              setVisualState(true, "Delivered at 2:14 pm · Front porch", "Arrived", "");
              if (simBtn) simBtn.disabled = false;
              if (status) status.textContent = `Order delivered by ${courierName} at 2:14 pm.`;
            });
          }, 180);
        });
      });

      msgToggle?.addEventListener("click", () => {
        if (!msgForm) return;
        const open = msgForm.hidden;
        msgForm.hidden = !open;
        msgToggle.setAttribute("aria-expanded", String(open));
        if (open) msgInput?.focus();
      });

      root.querySelectorAll<HTMLButtonElement>("[data-ord-quick]").forEach((btn) => {
        btn.addEventListener("click", () => {
          if (msgInput) {
            msgInput.value = btn.dataset.ordQuick ?? "";
            msgInput.focus();
          }
        });
      });

      msgForm?.addEventListener("submit", (ev) => {
        ev.preventDefault();
        const text = msgInput?.value.trim() ?? "";
        if (!text) {
          if (status) status.textContent = `Type a message for ${courierName} first.`;
          msgInput?.focus();
          return;
        }
        if (sentNote) {
          sentNote.textContent = `Sent to ${courierName}: "${text}"`;
          sentNote.hidden = false;
        }
        if (msgInput) msgInput.value = "";
        msgForm.hidden = true;
        msgToggle?.setAttribute("aria-expanded", "false");
        if (status) status.textContent = `Message sent to ${courierName}.`;
      });
    });
  }

  initAiOrderStatus();
  document.addEventListener("astro:page-load", initAiOrderStatus);
</script>
```
