{
  "name": "ai-order-status",
  "type": "registry:component",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "files": [
    {
      "type": "registry:component",
      "content": "\"use client\";\n\n/**\n * @author: @kokonutui\n * @description: AI Order Status\n * @version: 1.1.0\n * @date: 2026-11-05\n * @license: MIT\n * @website: https://kokonutui.com\n * @github: https://github.com/kokonut-labs/kokonutui\n */\n\nimport { Bike, Check, Home, MessageCircle, Store } from \"lucide-react\";\nimport {\n  AnimatePresence,\n  animate,\n  MotionConfig,\n  motion,\n  useMotionValue,\n  useMotionValueEvent,\n  useReducedMotion,\n} from \"motion/react\";\nimport {\n  type ReactNode,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface DeliveryOrder {\n  merchant: string;\n  orderId: string;\n  courier: string;\n  vehicle: string;\n  /** Minutes left. Live, pass the latest ETA; the demo counts down from it. */\n  minutes: number;\n  /** How far along the route the courier is, 0 to 1. */\n  progress: number;\n  /** When it should arrive, as shown. */\n  arriveAt: string;\n}\n\n/** Where the order is, from your delivery provider. */\nexport type OrderStatus = \"on-the-way\" | \"delivered\";\n\nexport interface AIOrderStatusProps {\n  /** The user's message, drawn as a bubble. Only the demo draws one by default. */\n  prompt?: string;\n  /** What the assistant says above the card. */\n  message?: string;\n  order?: DeliveryOrder;\n  /**\n   * Pass it to drive the card from your tracking updates: the courier\n   * glides to each new `progress` and the ETA shows `minutes` as given.\n   * Leave it out and the ETA counts down on `minuteMs`.\n   */\n  status?: OrderStatus;\n  /** Shown once it has arrived. */\n  delivered?: string;\n  /** Demo only: real ms per minute of ETA. */\n  minuteMs?: number;\n  /** Shows a Message button for reaching the courier. */\n  onMessage?: () => void;\n  className?: string;\n}\n\nconst EASE_OUT = [0.23, 1, 0.32, 1] as const;\nconst W = 320;\nconst H = 96;\nconst ROUTE = \"M28 70 C 72 70, 82 30, 128 30 S 182 72, 226 64 S 270 26, 292 26\";\nconst START = { x: 28, y: 70 };\nconst END = { x: 292, y: 26 };\n\nconst DEMO_ORDER: DeliveryOrder = {\n  merchant: \"Bloom & Stem\",\n  orderId: \"4821\",\n  courier: \"Leo\",\n  vehicle: \"Grey scooter\",\n  minutes: 12,\n  progress: 0.42,\n  arriveAt: \"2:14 pm\",\n};\n\nconst DEMO = {\n  prompt: \"Where are my flowers?\",\n  message: \"They’re on the way with Leo. I’ll keep this updated.\",\n  delivered:\n    \"Delivered. Leo left them with the concierge, and the card is tucked in the front.\",\n};\n\n/** The chat text around the card: the demo's only when it's the demo. */\nfunction shownText(\n  text: Pick<AIOrderStatusProps, \"prompt\" | \"message\" | \"delivered\">,\n  isDemo: boolean\n) {\n  if (!isDemo) {\n    return text;\n  }\n  return {\n    prompt: text.prompt ?? DEMO.prompt,\n    message: text.message ?? DEMO.message,\n    delivered: text.delivered ?? DEMO.delivered,\n  };\n}\n\n/**\n * The ETA and the courier's place on the route. Live, both follow `order`;\n * in the demo the ETA counts down and the courier moves with it.\n */\nfunction useEta(\n  order: DeliveryOrder,\n  status: OrderStatus | undefined,\n  minuteMs: number,\n  reduce: boolean\n) {\n  const driven = status !== undefined;\n  const [counted, setMinutes] = useState(order.minutes);\n  const minutes = driven ? order.minutes : counted;\n  const arrived = driven ? status === \"delivered\" : minutes <= 0;\n  const progress = useMotionValue(order.progress);\n  // Live: glides the courier to each new position you report.\n  useEffect(() => {\n    if (!driven) {\n      return;\n    }\n    const controls = animate(progress, arrived ? 1 : order.progress, {\n      duration: reduce ? 0 : 0.8,\n      ease: EASE_OUT,\n    });\n    return () => controls.stop();\n  }, [driven, arrived, order.progress, progress, reduce]);\n\n  // Demo: counts the ETA down, and moves the courier with it.\n  useEffect(() => {\n    if (arrived || driven) {\n      return;\n    }\n    const t = setTimeout(() => {\n      const next = minutes - 1;\n      setMinutes(next);\n      const target =\n        order.progress + (1 - order.progress) * (1 - next / order.minutes);\n      animate(progress, target, {\n        duration: reduce ? 0 : minuteMs / 1000,\n        ease: \"linear\",\n      });\n    }, minuteMs);\n    return () => clearTimeout(t);\n  }, [minutes, arrived, minuteMs, order, progress, reduce, driven]);\n\n  return { minutes, arrived, progress };\n}\n\nexport default function AIOrderStatus({\n  prompt,\n  message,\n  order = DEMO_ORDER,\n  status,\n  delivered,\n  minuteMs = 700,\n  onMessage,\n  className,\n}: AIOrderStatusProps) {\n  const reduce = useReducedMotion();\n  const driven = status !== undefined;\n  const isDemo = !driven && order === DEMO_ORDER;\n  const shown = shownText({ prompt, message, delivered }, isDemo);\n  const { minutes, arrived, progress } = useEta(\n    order,\n    status,\n    minuteMs,\n    Boolean(reduce)\n  );\n  const x = useMotionValue(START.x);\n  const y = useMotionValue(START.y);\n  const pathRef = useRef<SVGPathElement>(null);\n\n  // Keeps the courier on the route as progress moves.\n  const place = (v: number) => {\n    const path = pathRef.current;\n    if (!path) {\n      return;\n    }\n    const point = path.getPointAtLength(v * path.getTotalLength());\n    x.set(point.x);\n    y.set(point.y);\n  };\n  useMotionValueEvent(progress, \"change\", place);\n  // biome-ignore lint/correctness/useExhaustiveDependencies: places once on mount\n  useLayoutEffect(() => place(progress.get()), []);\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <div\n        className={cn(\"flex w-full max-w-md flex-col gap-4\", className)}\n        data-state={arrived ? \"delivered\" : \"on-the-way\"}\n      >\n        {shown.prompt ? (\n          <p className=\"max-w-[85%] self-end rounded-2xl rounded-br-md bg-zinc-100 px-3.5 py-2 text-[14px] text-zinc-800 leading-snug dark:bg-zinc-800 dark:text-zinc-100\">\n            {shown.prompt}\n          </p>\n        ) : null}\n        {shown.message ? (\n          <p className=\"text-[15px] text-zinc-800 leading-7 dark:text-zinc-200\">\n            {shown.message}\n          </p>\n        ) : null}\n\n        <div className=\"rounded-[22px] bg-black/[0.04] p-1 dark:bg-white/[0.06]\">\n          <div className=\"flex h-8 items-center justify-between px-3 text-[12px] text-zinc-500 dark:text-zinc-400\">\n            <span className=\"truncate\">\n              <span className=\"font-medium text-zinc-700 dark:text-zinc-300\">\n                {order.merchant}\n              </span>{\" \"}\n              · Order #{order.orderId}\n            </span>\n            <span className=\"flex shrink-0 items-center gap-1.5\">\n              <span\n                className={cn(\n                  \"size-1.5 rounded-full transition-colors duration-300\",\n                  arrived ? \"bg-emerald-500\" : \"bg-blue-500\"\n                )}\n              />\n              {arrived ? \"Delivered\" : \"Live\"}\n            </span>\n          </div>\n\n          <div className=\"overflow-hidden rounded-[18px] bg-white shadow-[0_1px_2px_rgb(0_0_0/0.04)] ring-1 ring-black/[0.06] dark:bg-zinc-900 dark:ring-white/[0.08]\">\n            <div className=\"flex items-end justify-between gap-3 px-4 pt-3.5\">\n              <div className=\"min-w-0\">\n                <p className=\"text-[12px] text-zinc-500 dark:text-zinc-400\">\n                  {arrived\n                    ? `Arrived at ${order.arriveAt}`\n                    : `Arriving around ${order.arriveAt}`}\n                </p>\n                <div className=\"mt-0.5 h-8 overflow-hidden font-semibold text-[26px] text-zinc-900 tracking-tight dark:text-zinc-100\">\n                  <AnimatePresence initial={false} mode=\"popLayout\">\n                    <motion.span\n                      animate={{ y: 0, opacity: 1, filter: \"blur(0px)\" }}\n                      className=\"block leading-8\"\n                      exit={{ y: -14, opacity: 0, filter: \"blur(2px)\" }}\n                      initial={{ y: 14, opacity: 0, filter: \"blur(2px)\" }}\n                      key={arrived ? \"done\" : minutes}\n                      transition={{ duration: 0.3, ease: EASE_OUT }}\n                    >\n                      {arrived ? (\n                        \"Delivered\"\n                      ) : (\n                        <>\n                          <span className=\"tabular-nums\">{minutes}</span>\n                          <span className=\"ml-1 font-medium text-[15px] text-zinc-500 tracking-normal dark:text-zinc-400\">\n                            min\n                          </span>\n                        </>\n                      )}\n                    </motion.span>\n                  </AnimatePresence>\n                </div>\n              </div>\n              <Steps arrived={arrived} />\n            </div>\n\n            <div className=\"relative mt-2\">\n              <svg\n                aria-hidden=\"true\"\n                className=\"block h-auto w-full\"\n                viewBox={`0 0 ${W} ${H}`}\n              >\n                <g className=\"stroke-zinc-100 dark:stroke-white/[0.05]\">\n                  <path d=\"M0 48 H320\" strokeWidth=\"6\" />\n                  <path d=\"M96 0 V96\" strokeWidth=\"5\" />\n                  <path d=\"M200 0 L250 96\" strokeWidth=\"5\" />\n                  <path d=\"M0 14 L140 4\" strokeWidth=\"4\" />\n                </g>\n                <path\n                  className=\"stroke-zinc-300 dark:stroke-zinc-600\"\n                  d={ROUTE}\n                  fill=\"none\"\n                  ref={pathRef}\n                  strokeDasharray=\"2 5\"\n                  strokeLinecap=\"round\"\n                  strokeWidth=\"2\"\n                />\n                <motion.path\n                  className={cn(\n                    \"transition-colors duration-500\",\n                    arrived\n                      ? \"stroke-emerald-500\"\n                      : \"stroke-zinc-900 dark:stroke-zinc-100\"\n                  )}\n                  d={ROUTE}\n                  fill=\"none\"\n                  strokeLinecap=\"round\"\n                  strokeWidth=\"2.5\"\n                  style={{ pathLength: progress }}\n                />\n                <Pin x={START.x} y={START.y}>\n                  <Store height={11} width={11} x={-5.5} y={-5.5} />\n                </Pin>\n                <Pin done={arrived} x={END.x} y={END.y}>\n                  <AnimatePresence initial={false} mode=\"popLayout\">\n                    <motion.g\n                      animate={{ opacity: 1 }}\n                      exit={{ opacity: 0 }}\n                      initial={{ opacity: 0 }}\n                      key={arrived ? \"check\" : \"home\"}\n                      transition={{ duration: 0.2, delay: arrived ? 0.15 : 0 }}\n                    >\n                      {arrived ? (\n                        <Check\n                          height={12}\n                          strokeWidth={3}\n                          width={12}\n                          x={-6}\n                          y={-6}\n                        />\n                      ) : (\n                        <Home height={11} width={11} x={-5.5} y={-5.5} />\n                      )}\n                    </motion.g>\n                  </AnimatePresence>\n                </Pin>\n                <AnimatePresence>\n                  {!arrived && (\n                    <motion.g exit={{ opacity: 0 }} style={{ x, y }}>\n                      <circle\n                        className=\"fill-zinc-900 dark:fill-white\"\n                        r=\"12\"\n                      />\n                      <Bike\n                        className=\"text-white dark:text-zinc-900\"\n                        height={13}\n                        width={13}\n                        x={-6.5}\n                        y={-6.5}\n                      />\n                    </motion.g>\n                  )}\n                </AnimatePresence>\n              </svg>\n            </div>\n\n            <CourierRow\n              onMessage={onMessage ?? (isDemo ? () => undefined : undefined)}\n              order={order}\n            />\n          </div>\n        </div>\n\n        <AnimatePresence>\n          {arrived && shown.delivered ? (\n            <motion.p\n              animate={{ opacity: 1, filter: \"blur(0px)\", y: 0 }}\n              className=\"text-[15px] text-zinc-800 leading-7 dark:text-zinc-200\"\n              initial={{ opacity: 0, filter: \"blur(4px)\", y: 4 }}\n              transition={{ duration: 0.4, ease: EASE_OUT, delay: 0.5 }}\n            >\n              {shown.delivered}\n            </motion.p>\n          ) : null}\n        </AnimatePresence>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {arrived ? \"Delivered\" : \"\"}\n        </p>\n      </div>\n    </MotionConfig>\n  );\n}\n\n/** The courier, with a Message button when you pass `onMessage`. */\nfunction CourierRow({\n  order,\n  onMessage,\n}: {\n  order: DeliveryOrder;\n  onMessage?: () => void;\n}) {\n  return (\n    <div className=\"flex items-center gap-3 border-black/[0.06] border-t px-4 py-3 dark:border-white/[0.08]\">\n      <span className=\"flex size-8 shrink-0 items-center justify-center rounded-full bg-sky-100 font-semibold text-[12px] text-sky-800 dark:bg-sky-500/20 dark:text-sky-200\">\n        {order.courier.slice(0, 1)}\n      </span>\n      <span className=\"min-w-0 flex-1\">\n        <span className=\"block truncate font-medium text-[13.5px] text-zinc-900 dark:text-zinc-100\">\n          {order.courier}\n        </span>\n        <span className=\"block truncate text-[12px] text-zinc-500 dark:text-zinc-400\">\n          {order.vehicle}\n        </span>\n      </span>\n      {onMessage ? (\n        <button\n          className=\"flex h-8 items-center gap-1.5 rounded-full px-3 font-medium text-[12.5px] text-zinc-700 outline-hidden ring-1 ring-black/[0.08] transition-colors duration-150 hover:bg-zinc-50 focus-visible:ring-2 focus-visible:ring-blue-500/50 active:bg-zinc-100 dark:text-zinc-200 dark:ring-white/10 dark:active:bg-white/[0.08] dark:hover:bg-white/[0.05]\"\n          onClick={onMessage}\n          type=\"button\"\n        >\n          <MessageCircle aria-hidden=\"true\" className=\"size-3.5\" />\n          Message\n        </button>\n      ) : null}\n    </div>\n  );\n}\n\nconst STEPS = [\"Packed\", \"On the way\", \"Delivered\"];\n\n/** Three short ticks under the ETA: where the order is at a glance. */\nfunction Steps({ arrived }: { arrived: boolean }) {\n  const at = arrived ? 2 : 1;\n  return (\n    <ol className=\"mb-1.5 flex shrink-0 gap-1\" title={STEPS[at]}>\n      {STEPS.map((s, i) => (\n        <li\n          aria-current={i === at ? \"step\" : undefined}\n          className=\"relative h-1 w-6 overflow-hidden rounded-full bg-zinc-200 dark:bg-zinc-700\"\n          key={s}\n        >\n          <span className=\"sr-only\">{s}</span>\n          <motion.span\n            animate={{ scaleX: i <= at ? 1 : 0 }}\n            className={cn(\n              \"absolute inset-0 origin-left rounded-full\",\n              arrived ? \"bg-emerald-500\" : \"bg-zinc-900 dark:bg-zinc-100\"\n            )}\n            initial={false}\n            transition={{ duration: 0.4, ease: EASE_OUT }}\n          />\n        </li>\n      ))}\n    </ol>\n  );\n}\n\nfunction Pin({\n  x,\n  y,\n  done = false,\n  children,\n}: {\n  x: number;\n  y: number;\n  done?: boolean;\n  children: ReactNode;\n}) {\n  return (\n    <g transform={`translate(${x} ${y})`}>\n      <circle\n        className={cn(\n          \"transition-colors duration-500\",\n          done\n            ? \"fill-emerald-500 stroke-emerald-500\"\n            : \"fill-white stroke-zinc-300 dark:fill-zinc-900 dark:stroke-zinc-600\"\n        )}\n        r=\"11\"\n        strokeWidth=\"1.5\"\n      />\n      <g\n        className={cn(\n          \"transition-colors duration-500\",\n          done ? \"text-white\" : \"text-zinc-500 dark:text-zinc-400\"\n        )}\n      >\n        {children}\n      </g>\n    </g>\n  );\n}\n",
      "path": "/components/kokonutui/ai-order-status.tsx",
      "target": "components/kokonutui/ai-order-status.tsx"
    }
  ]
}