{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "order-summary-block",
  "title": "Order Summary Block",
  "description": "An editable order summary card: line items with thumbnails, quantity steppers, struck-through original prices and remove with undo, 'show more' for long orders, a gift-wrap option with a note, a delivery estimate worked out in business days, collapsible price details, a counting total and a savings callout.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/order-summary-block/order-summary-block.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, animate, motion, useMotionValue, useReducedMotion, useTransform } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface SummaryLine {\n  id: string;\n  title: string;\n  variant: string;\n  price: number;\n  compareAtPrice?: number;\n  quantity: number;\n  image?: string;\n}\n\nexport interface OrderSummaryBlockProps {\n  lines?: SummaryLine[];\n  currency?: string;\n  shipping?: number;\n  taxRate?: number;\n  giftWrapPrice?: number;\n  /** Business days until delivery, as [min, max]. Dates are worked out in the browser. */\n  deliveryDays?: [number, number];\n  ctaLabel?: string;\n  onContinue?: (summary: { lines: SummaryLine[]; gift: { wrap: boolean; message: string }; total: number }) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", title: \"#FFFFFF\", muted: \"rgba(255,255,255,0.45)\", body: \"rgba(255,255,255,0.62)\", line: \"rgba(255,255,255,0.12)\", card: \"#141414\", well: \"rgba(255,255,255,0.04)\", input: \"#0F0F0F\", photo: \"#F1F1F1\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", ring: \"rgba(255,255,255,0.5)\" },\n  light: { bg: \"#FFFFFF\", title: \"#111111\", muted: \"rgba(0,0,0,0.45)\", body: \"rgba(0,0,0,0.62)\", line: \"rgba(0,0,0,0.1)\", card: \"#F7F7F6\", well: \"rgba(0,0,0,0.03)\", input: \"#FFFFFF\", photo: \"#F1F1F1\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst LINES: SummaryLine[] = [\n  { id: \"stand\", title: \"Laptop Stand\", variant: \"Space black\", price: 49, compareAtPrice: 89, quantity: 1, image: \"/demo/laptop-stand.webp\" },\n  { id: \"notebook\", title: \"Premium Notebook\", variant: \"A5 · Dotted\", price: 24, quantity: 2, image: \"/demo/notebook.webp\" },\n  { id: \"watch\", title: \"Minimal Watch\", variant: \"Black · 40mm\", price: 79, compareAtPrice: 129, quantity: 1, image: \"/demo/minimal-watch.webp\" },\n  { id: \"bottle\", title: \"Insulated Water Bottle\", variant: \"750 ml\", price: 39, quantity: 1, image: \"/demo/insulated-water-bottle.webp\" },\n];\nconst DAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\nconst MONTHS = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"];\n\nfunction addBusinessDays(from: Date, n: number) {\n  const d = new Date(from);\n  let left = n;\n  while (left > 0) {\n    d.setDate(d.getDate() + 1);\n    if (d.getDay() !== 0 && d.getDay() !== 6) left--;\n  }\n  return `${DAYS[d.getDay()]}, ${MONTHS[d.getMonth()]} ${d.getDate()}`;\n}\n\nfunction Money({ value, currency, reduce }: { value: number; currency: string; reduce: boolean }) {\n  const mv = useMotionValue(value);\n  const text = useTransform(mv, (v) => `${currency}${v.toFixed(2)}`);\n  React.useEffect(() => {\n    if (reduce) {\n      mv.set(value);\n      return;\n    }\n    const c = animate(mv, value, { duration: 0.45, ease: [0.22, 1, 0.36, 1] });\n    return () => c.stop();\n  }, [value, reduce, mv]);\n  return <motion.span>{text}</motion.span>;\n}\n\nexport function OrderSummaryBlock({ lines: initial = LINES, currency = \"$\", shipping = 0, taxRate = 0.08, giftWrapPrice = 5, deliveryDays = [2, 4], ctaLabel = \"Continue to payment\", onContinue, theme = \"dark\", className }: OrderSummaryBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [lines, setLines] = React.useState(initial);\n  const [expanded, setExpanded] = React.useState(false);\n  const [removed, setRemoved] = React.useState<{ line: SummaryLine; index: number } | null>(null);\n  const [wrap, setWrap] = React.useState(false);\n  const [message, setMessage] = React.useState(\"\");\n  const [detailsOpen, setDetailsOpen] = React.useState(true);\n  const [eta, setEta] = React.useState<string | null>(null);\n\n  React.useEffect(() => {\n    const t = setTimeout(() => setEta(`${addBusinessDays(new Date(), deliveryDays[0])} – ${addBusinessDays(new Date(), deliveryDays[1])}`), 0);\n    return () => clearTimeout(t);\n  }, [deliveryDays]);\n  React.useEffect(() => {\n    if (!removed) return;\n    const t = setTimeout(() => setRemoved(null), 4000);\n    return () => clearTimeout(t);\n  }, [removed]);\n\n  const count = lines.reduce((a, l) => a + l.quantity, 0);\n  const subtotal = lines.reduce((a, l) => a + l.price * l.quantity, 0);\n  const savings = lines.reduce((a, l) => a + (l.compareAtPrice ? (l.compareAtPrice - l.price) * l.quantity : 0), 0);\n  const gift = wrap ? giftWrapPrice : 0;\n  const tax = (subtotal + gift) * taxRate;\n  const total = subtotal + gift + shipping + tax;\n  const money = (n: number) => `${currency}${n.toFixed(2)}`;\n  const visible = expanded ? lines : lines.slice(0, 2);\n  const hidden = lines.length - visible.length;\n\n  const setQty = (id: string, q: number) => setLines((l) => l.map((x) => (x.id === id ? { ...x, quantity: Math.max(1, Math.min(9, q)) } : x)));\n  const remove = (id: string) => {\n    const index = lines.findIndex((l) => l.id === id);\n    if (index < 0) return;\n    setRemoved({ line: lines[index], index });\n    setLines((l) => l.filter((x) => x.id !== id));\n  };\n  const undo = () => {\n    if (!removed) return;\n    setLines((l) => [...l.slice(0, removed.index), removed.line, ...l.slice(removed.index)]);\n    setRemoved(null);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }}>\n      <div className=\"mx-auto max-w-[520px] px-4 py-10\">\n        <div className=\"rounded-3xl border\" style={{ background: p.card, borderColor: p.line }}>\n          <div className=\"flex items-baseline justify-between px-5 pt-5\">\n            <h2 className=\"m-0 text-[18px] font-semibold\">Order summary</h2>\n            <span className=\"text-[12.5px] tabular-nums\" style={{ color: p.muted }} aria-live=\"polite\">\n              {count} {count === 1 ? \"item\" : \"items\"}\n            </span>\n          </div>\n\n          <ul className=\"m-0 mt-3 list-none px-5 py-0\">\n            <AnimatePresence initial={false}>\n              {visible.map((l) => (\n                <motion.li key={l.id} initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0, x: 24 }} transition={{ duration: 0.28, ease: [0.22, 1, 0.36, 1] }} className=\"overflow-hidden\">\n                  <div className=\"flex items-center gap-3 border-b py-3\" style={{ borderColor: p.line }}>\n                    <span className=\"h-16 w-16 shrink-0 overflow-hidden rounded-xl\" style={{ background: p.photo }}>\n                      {/* eslint-disable-next-line @next/next/no-img-element */}\n                      {l.image && <img src={l.image} alt=\"\" className=\"h-full w-full object-cover\" />}\n                    </span>\n                    <span className=\"min-w-0 flex-1\">\n                      <span className=\"block truncate text-[14px] font-medium\">{l.title}</span>\n                      <span className=\"block text-[12px]\" style={{ color: p.muted }}>\n                        {l.variant}\n                      </span>\n                      <span className=\"mt-1.5 flex items-center gap-2\">\n                        <span className=\"flex h-7 items-center rounded-full border\" style={{ borderColor: p.line }}>\n                          <button type=\"button\" onClick={() => setQty(l.id, l.quantity - 1)} disabled={l.quantity <= 1} aria-label={`Decrease ${l.title}`} className={cn(\"grid h-7 w-7 cursor-pointer place-items-center rounded-l-full border-0 bg-transparent text-[14px] disabled:opacity-30\", focus)} style={{ color: p.title, ...ring }}>\n                            −\n                          </button>\n                          <span className=\"w-5 text-center text-[12.5px] tabular-nums\">{l.quantity}</span>\n                          <button type=\"button\" onClick={() => setQty(l.id, l.quantity + 1)} aria-label={`Increase ${l.title}`} className={cn(\"grid h-7 w-7 cursor-pointer place-items-center rounded-r-full border-0 bg-transparent text-[14px]\", focus)} style={{ color: p.title, ...ring }}>\n                            +\n                          </button>\n                        </span>\n                        <button type=\"button\" onClick={() => remove(l.id)} className={cn(\"cursor-pointer border-0 bg-transparent p-0 text-[12px] underline-offset-2 hover:underline\", focus)} style={{ color: p.muted, ...ring }}>\n                          Remove\n                        </button>\n                      </span>\n                    </span>\n                    <span className=\"shrink-0 text-right\">\n                      <span className=\"block text-[14px] font-medium tabular-nums\">{money(l.price * l.quantity)}</span>\n                      {l.compareAtPrice && (\n                        <span className=\"block text-[12px] tabular-nums line-through\" style={{ color: p.muted }}>\n                          {money(l.compareAtPrice * l.quantity)}\n                        </span>\n                      )}\n                    </span>\n                  </div>\n                </motion.li>\n              ))}\n            </AnimatePresence>\n          </ul>\n          {(hidden > 0 || expanded) && lines.length > 2 && (\n            <button type=\"button\" onClick={() => setExpanded((e) => !e)} aria-expanded={expanded} className={cn(\"mx-5 mt-2 flex cursor-pointer items-center gap-1.5 border-0 bg-transparent p-0 text-[13px] font-medium\", focus)} style={{ color: p.body, ...ring }}>\n              {expanded ? \"Show less\" : `Show ${hidden} more ${hidden === 1 ? \"item\" : \"items\"}`}\n              <motion.svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" animate={{ rotate: expanded ? 180 : 0 }} aria-hidden=\"true\">\n                <path d=\"m6 9 6 6 6-6\" />\n              </motion.svg>\n            </button>\n          )}\n          <AnimatePresence>\n            {removed && (\n              <motion.div key=\"undo\" initial={reduce ? false : { opacity: 0, height: 0 }} animate={{ opacity: 1, height: \"auto\" }} exit={reduce ? undefined : { opacity: 0, height: 0 }} className=\"overflow-hidden px-5\" role=\"status\">\n                <div className=\"mt-3 flex items-center justify-between rounded-xl px-3 py-2 text-[12.5px]\" style={{ background: p.well, color: p.body }}>\n                  <span className=\"truncate\">Removed {removed.line.title}</span>\n                  <button type=\"button\" onClick={undo} className={cn(\"cursor-pointer border-0 bg-transparent p-0 text-[12.5px] font-semibold\", focus)} style={{ color: p.title, ...ring }}>\n                    Undo\n                  </button>\n                </div>\n              </motion.div>\n            )}\n          </AnimatePresence>\n\n          <div className=\"mx-5 mt-4 rounded-2xl border\" style={{ borderColor: wrap ? p.title : p.line }}>\n            <label className=\"flex cursor-pointer items-center gap-3 px-3.5 py-3 has-[:focus-visible]:ring-2\" style={ring}>\n              <input type=\"checkbox\" checked={wrap} onChange={(e) => setWrap(e.target.checked)} className=\"h-4 w-4 cursor-pointer\" style={{ accentColor: p.title }} />\n              <span className=\"flex-1 text-[13.5px]\">\n                🎁 Gift wrap with a note\n                <span className=\"block text-[12px]\" style={{ color: p.muted }}>\n                  Recycled paper, prices hidden on the receipt\n                </span>\n              </span>\n              <span className=\"text-[13px] tabular-nums\" style={{ color: p.muted }}>\n                +{money(giftWrapPrice)}\n              </span>\n            </label>\n            <AnimatePresence initial={false}>\n              {wrap && (\n                <motion.div key=\"msg\" initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} className=\"overflow-hidden\">\n                  <div className=\"px-3.5 pb-3.5\">\n                    <label htmlFor={`${uid}-msg`} className=\"sr-only\">\n                      Gift message\n                    </label>\n                    <textarea id={`${uid}-msg`} value={message} onChange={(e) => setMessage(e.target.value.slice(0, 150))} rows={2} placeholder=\"Write a short message…\" className=\"w-full resize-none rounded-xl border px-3 py-2 text-[13px] outline-none focus-visible:ring-2\" style={{ background: p.input, borderColor: p.line, color: p.title, ...ring }} />\n                    <p className=\"m-0 text-right text-[11px] tabular-nums\" style={{ color: p.muted }}>\n                      {message.length}/150\n                    </p>\n                  </div>\n                </motion.div>\n              )}\n            </AnimatePresence>\n          </div>\n\n          <div className=\"mx-5 mt-4 flex items-center gap-3 rounded-2xl px-3.5 py-3\" style={{ background: p.well }}>\n            <svg width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.title} strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M3 7h11v9H3zM14 10h4l3 3v3h-7M7 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM17 19a2 2 0 1 0 0-4 2 2 0 0 0 0 4z\" />\n            </svg>\n            <span className=\"text-[13px]\">\n              <span className=\"block font-medium\">Arrives {eta ?? \"in 2–4 business days\"}</span>\n              <span className=\"block text-[12px]\" style={{ color: p.muted }}>\n                {shipping ? `Standard shipping ${money(shipping)}` : \"Free standard shipping\"}\n              </span>\n            </span>\n          </div>\n\n          <div className=\"px-5 pt-4 pb-5\">\n            <button type=\"button\" onClick={() => setDetailsOpen((o) => !o)} aria-expanded={detailsOpen} aria-controls={`${uid}-details`} className={cn(\"flex w-full cursor-pointer items-center justify-between border-0 bg-transparent p-0 text-[13px]\", focus)} style={{ color: p.body, ...ring }}>\n              Price details\n              <motion.svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"round\" animate={{ rotate: detailsOpen ? 180 : 0 }} aria-hidden=\"true\">\n                <path d=\"m6 9 6 6 6-6\" />\n              </motion.svg>\n            </button>\n            <AnimatePresence initial={false}>\n              {detailsOpen && (\n                <motion.dl key=\"d\" id={`${uid}-details`} initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} className=\"m-0 overflow-hidden text-[13.5px]\">\n                  {[\n                    [\"Subtotal\", money(subtotal)],\n                    ...(wrap ? [[\"Gift wrap\", money(gift)]] : []),\n                    [\"Shipping\", shipping ? money(shipping) : \"Free\"],\n                    [`Estimated tax`, money(tax)],\n                  ].map(([k, v]) => (\n                    <div key={k} className=\"flex justify-between pt-2\">\n                      <dt style={{ color: p.body }}>{k}</dt>\n                      <dd className=\"m-0 tabular-nums\">{v}</dd>\n                    </div>\n                  ))}\n                </motion.dl>\n              )}\n            </AnimatePresence>\n            <div className=\"mt-3 flex items-baseline justify-between border-t pt-3\" style={{ borderColor: p.line }}>\n              <span className=\"text-[15px] font-semibold\">Total</span>\n              <span className=\"text-[24px] font-semibold tracking-[-0.02em] tabular-nums\">\n                <Money value={total} currency={currency} reduce={reduce} />\n              </span>\n            </div>\n            <AnimatePresence initial={false}>\n              {savings > 0 && (\n                <motion.p key=\"save\" initial={reduce ? false : { opacity: 0, y: -4 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"m-0 mt-2 rounded-xl px-3 py-2 text-center text-[12.5px] font-medium\" style={{ background: `${p.accent}1A`, color: p.accent }}>\n                  You&apos;re saving <Money value={savings} currency={currency} reduce={reduce} /> on this order\n                </motion.p>\n              )}\n            </AnimatePresence>\n            <button type=\"button\" onClick={() => onContinue?.({ lines, gift: { wrap, message }, total })} disabled={!lines.length} className={cn(\"mt-4 flex h-12 w-full cursor-pointer items-center justify-center gap-2 rounded-full border-0 text-[15px] font-semibold disabled:cursor-not-allowed disabled:opacity-40\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n              {ctaLabel} →\n            </button>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default OrderSummaryBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}