{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gift-card-block",
  "title": "Gift Card Block",
  "description": "A digital gift card section: a live card preview that tilts with the pointer and updates as you type, four code-drawn designs, preset and custom amounts with limits, recipient, sender, send-now-or-later and a message, add to cart, plus a 'Check balance' tab.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/gift-card-block/gift-card-block.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useMotionValue, useReducedMotion, useSpring, 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 GiftCardOrder {\n  amount: number;\n  design: string;\n  to: string;\n  email: string;\n  from: string;\n  message: string;\n  sendOn: \"now\" | \"later\";\n}\n\nexport interface GiftCardBlockProps {\n  store?: string;\n  amounts?: number[];\n  min?: number;\n  max?: number;\n  currency?: string;\n  /** Demo balances for the balance checker: code → amount. */\n  balances?: Record<string, number>;\n  onAddToCart?: (order: GiftCardOrder) => void | Promise<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\", input: \"#0F0F0F\", buttonBg: \"#FFFFFF\", buttonText: \"#111111\", accent: \"#7CDE6A\", error: \"#FF6B57\", 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\", input: \"#FFFFFF\", buttonBg: \"#111111\", buttonText: \"#FFFFFF\", accent: \"#2F9E44\", error: \"#D9480F\", ring: \"rgba(0,0,0,0.45)\" },\n};\nconst DESIGNS: { id: string; label: string; bg: string; ink: string; sub: string; deco: \"rings\" | \"grid\" | \"dots\" | \"wave\" }[] = [\n  { id: \"mono\", label: \"Mono\", bg: \"linear-gradient(135deg,#161616,#2A2A2A)\", ink: \"#FFFFFF\", sub: \"#7CDE6A\", deco: \"rings\" },\n  { id: \"paper\", label: \"Paper\", bg: \"linear-gradient(135deg,#F4F1EA,#E4DED2)\", ink: \"#111111\", sub: \"#8A7F6C\", deco: \"grid\" },\n  { id: \"dusk\", label: \"Dusk\", bg: \"linear-gradient(135deg,#2B1B4A,#C2577A 70%,#F2A65A)\", ink: \"#FFFFFF\", sub: \"rgba(255,255,255,0.75)\", deco: \"wave\" },\n  { id: \"mint\", label: \"Mint\", bg: \"linear-gradient(135deg,#BFF3D3,#7CDE6A)\", ink: \"#0A0A0A\", sub: \"rgba(10,10,10,0.6)\", deco: \"dots\" },\n];\n\nfunction Deco({ kind, color }: { kind: string; color: string }) {\n  if (kind === \"rings\")\n    return (\n      <svg className=\"absolute -right-10 -bottom-16 h-64 w-64\" viewBox=\"0 0 200 200\" fill=\"none\" stroke={color} strokeOpacity=\"0.35\" aria-hidden=\"true\">\n        {[30, 55, 80, 105].map((r) => (\n          <circle key={r} cx=\"100\" cy=\"100\" r={r} />\n        ))}\n      </svg>\n    );\n  if (kind === \"grid\")\n    return (\n      <svg className=\"absolute inset-0 h-full w-full\" aria-hidden=\"true\">\n        <defs>\n          <pattern id=\"gc-grid\" width=\"22\" height=\"22\" patternUnits=\"userSpaceOnUse\">\n            <path d=\"M22 0H0V22\" fill=\"none\" stroke={color} strokeOpacity=\"0.25\" />\n          </pattern>\n        </defs>\n        <rect width=\"100%\" height=\"100%\" fill=\"url(#gc-grid)\" />\n      </svg>\n    );\n  if (kind === \"dots\")\n    return (\n      <svg className=\"absolute inset-0 h-full w-full\" aria-hidden=\"true\">\n        <defs>\n          <pattern id=\"gc-dots\" width=\"16\" height=\"16\" patternUnits=\"userSpaceOnUse\">\n            <circle cx=\"2\" cy=\"2\" r=\"1.6\" fill={color} fillOpacity=\"0.25\" />\n          </pattern>\n        </defs>\n        <rect width=\"100%\" height=\"100%\" fill=\"url(#gc-dots)\" />\n      </svg>\n    );\n  return (\n    <svg className=\"absolute inset-x-0 bottom-0 h-1/2 w-full\" viewBox=\"0 0 400 100\" preserveAspectRatio=\"none\" aria-hidden=\"true\">\n      <path d=\"M0 60 C80 20 160 100 240 60 S360 30 400 50 V100 H0Z\" fill=\"#FFFFFF\" fillOpacity=\"0.12\" />\n      <path d=\"M0 80 C100 50 180 110 280 75 S380 70 400 80 V100 H0Z\" fill=\"#FFFFFF\" fillOpacity=\"0.12\" />\n    </svg>\n  );\n}\n\nexport function GiftCardBlock({ store = \"Northline\", amounts = [25, 50, 100, 200], min = 10, max = 500, currency = \"$\", balances = { \"NL-4821-7730\": 37.5, \"NL-1100-2026\": 100 }, onAddToCart, theme = \"dark\", className }: GiftCardBlockProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [tab, setTab] = React.useState<\"buy\" | \"balance\">(\"buy\");\n  const [amount, setAmount] = React.useState(50);\n  const [custom, setCustom] = React.useState(\"\");\n  const [design, setDesign] = React.useState(DESIGNS[0].id);\n  const [o, setO] = React.useState({ to: \"\", email: \"\", from: \"\", message: \"\", sendOn: \"now\" as \"now\" | \"later\" });\n  const [state, setState] = React.useState<\"idle\" | \"loading\" | \"added\">(\"idle\");\n  const [touched, setTouched] = React.useState(false);\n  const [code, setCode] = React.useState(\"\");\n  const [balance, setBalance] = React.useState<null | { ok: boolean; value?: number }>(null);\n  const [checking, setChecking] = React.useState(false);\n\n  const mx = useMotionValue(0);\n  const my = useMotionValue(0);\n  const rx = useSpring(useTransform(my, (v) => v * -10), { stiffness: 200, damping: 20 });\n  const ry = useSpring(useTransform(mx, (v) => v * 12), { stiffness: 200, damping: 20 });\n  const glareX = useTransform(mx, (v) => `${50 + v * 40}%`);\n  const glare = useTransform(glareX, (gx) => `radial-gradient(circle at ${gx} 20%, rgba(255,255,255,0.35), transparent 55%)`);\n\n  React.useEffect(() => {\n    if (state !== \"added\") return;\n    const t = setTimeout(() => setState(\"idle\"), 2400);\n    return () => clearTimeout(t);\n  }, [state]);\n\n  const d = DESIGNS.find((x) => x.id === design) ?? DESIGNS[0];\n  const customVal = Number(custom);\n  const value = custom ? customVal : amount;\n  const amountError = custom && (customVal < min || customVal > max) ? `Choose between ${currency}${min} and ${currency}${max}` : null;\n  const emailError = !/^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/.test(o.email) ? \"Enter the recipient's email\" : null;\n  const valid = !amountError && value > 0 && !emailError && o.to.trim().length > 0;\n\n  const add = async () => {\n    setTouched(true);\n    if (!valid || state === \"loading\") return;\n    setState(\"loading\");\n    try {\n      await (onAddToCart ? onAddToCart({ amount: value, design, ...o }) : new Promise((r) => setTimeout(r, reduce ? 0 : 700)));\n      setState(\"added\");\n    } catch {\n      setState(\"idle\");\n    }\n  };\n  const check = (e: React.FormEvent) => {\n    e.preventDefault();\n    if (!code.trim()) return;\n    setChecking(true);\n    setTimeout(\n      () => {\n        const v = balances[code.trim().toUpperCase()];\n        setBalance(v !== undefined ? { ok: true, value: v } : { ok: false });\n        setChecking(false);\n      },\n      reduce ? 0 : 700,\n    );\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const input = \"h-11 w-full rounded-xl border px-3.5 text-[14px] outline-none focus-visible:ring-2\";\n  const inputStyle = (bad?: boolean) => ({ background: p.input, borderColor: bad ? p.error : p.line, color: p.title, ...ring });\n  const label = \"mb-1.5 block text-[12.5px] font-medium\";\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.title }}>\n      <div className=\"mx-auto grid max-w-6xl grid-cols-1 items-start gap-8 px-4 py-12 @[900px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)] @[900px]:gap-12 @[640px]:px-8\">\n        {/* Card preview */}\n        <div className=\"@[900px]:sticky @[900px]:top-8\">\n          <div\n            className=\"mx-auto w-full max-w-[480px]\"\n            style={{ perspective: 1000 }}\n            onPointerMove={(e) => {\n              if (reduce || e.pointerType === \"touch\") return;\n              const r = e.currentTarget.getBoundingClientRect();\n              mx.set((e.clientX - r.left) / r.width - 0.5);\n              my.set((e.clientY - r.top) / r.height - 0.5);\n            }}\n            onPointerLeave={() => {\n              mx.set(0);\n              my.set(0);\n            }}\n          >\n            <motion.div className=\"relative aspect-[1.6] w-full overflow-hidden rounded-[22px] shadow-[0_30px_60px_-25px_rgba(0,0,0,0.6)]\" style={{ background: d.bg, color: d.ink, rotateX: rx, rotateY: ry }} role=\"img\" aria-label={`${d.label} gift card, ${currency}${value || 0}${o.to ? ` for ${o.to}` : \"\"}`}>\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                <motion.div key={d.id} className=\"absolute inset-0\" initial={reduce ? false : { opacity: 0 }} animate={{ opacity: 1 }} exit={reduce ? undefined : { opacity: 0 }} transition={{ duration: 0.35 }}>\n                  <Deco kind={d.deco} color={d.ink} />\n                </motion.div>\n              </AnimatePresence>\n              <motion.span className=\"pointer-events-none absolute inset-0\" style={{ background: glare }} aria-hidden=\"true\" />\n              <div className=\"absolute inset-5 flex flex-col justify-between @[480px]:inset-6\">\n                <div className=\"flex items-start justify-between\">\n                  <span className=\"text-[15px] font-semibold tracking-[-0.01em]\">{store}</span>\n                  <span className=\"text-[11px] font-medium tracking-[0.12em] uppercase\" style={{ color: d.sub }}>\n                    Gift card\n                  </span>\n                </div>\n                <div>\n                  <AnimatePresence mode=\"popLayout\" initial={false}>\n                    <motion.p key={value} initial={reduce ? false : { opacity: 0, y: 14 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -14 }} className=\"m-0 text-[38px] leading-none font-semibold tracking-[-0.03em] tabular-nums @[480px]:text-[56px]\">\n                      {currency}\n                      {value || 0}\n                    </motion.p>\n                  </AnimatePresence>\n                  <p className=\"m-0 mt-2 min-h-[18px] truncate text-[13px]\" style={{ color: d.sub }}>\n                    {o.to ? `For ${o.to}` : \"For someone special\"}\n                    {o.from ? ` · from ${o.from}` : \"\"}\n                  </p>\n                </div>\n              </div>\n            </motion.div>\n          </div>\n          <AnimatePresence initial={false}>\n            {o.message && (\n              <motion.p key=\"msg\" initial={reduce ? false : { opacity: 0, y: -6 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"mx-auto mt-4 max-w-[480px] rounded-2xl border px-4 py-3 text-[13.5px] italic\" style={{ borderColor: p.line, color: p.body }}>\n                “{o.message}”\n              </motion.p>\n            )}\n          </AnimatePresence>\n          <div role=\"radiogroup\" aria-label=\"Card design\" className=\"mx-auto mt-4 flex max-w-[480px] gap-2\">\n            {DESIGNS.map((x) => (\n              <button key={x.id} type=\"button\" role=\"radio\" aria-checked={design === x.id} onClick={() => setDesign(x.id)} className={cn(\"flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-xl border-0 bg-transparent p-1\", focus)} style={{ color: design === x.id ? p.title : p.muted, ...ring }}>\n                <span className=\"block aspect-[1.6] w-full rounded-lg transition-shadow\" style={{ background: x.bg, boxShadow: design === x.id ? `0 0 0 2px ${p.bg}, 0 0 0 4px ${p.title}` : \"none\" }} />\n                <span className=\"text-[11.5px]\">{x.label}</span>\n              </button>\n            ))}\n          </div>\n        </div>\n\n        {/* Form */}\n        <div>\n          <h2 className=\"m-0 text-[30px] font-semibold tracking-[-0.03em] @[640px]:text-[38px]\">Give the gift of choice</h2>\n          <p className=\"m-0 mt-2 text-[14.5px]\" style={{ color: p.body }}>\n            Delivered by email, never expires, and works on everything in the store.\n          </p>\n          <div role=\"tablist\" aria-label=\"Gift cards\" className=\"mt-5 inline-flex rounded-full border p-1\" style={{ borderColor: p.line }}>\n            {([\"buy\", \"balance\"] as const).map((t) => (\n              <button key={t} type=\"button\" role=\"tab\" aria-selected={tab === t} onClick={() => setTab(t)} className={cn(\"relative h-8 cursor-pointer rounded-full border-0 bg-transparent px-4 text-[13px] font-medium\", focus)} style={{ color: tab === t ? p.buttonText : p.body, ...ring }}>\n                {tab === t && <motion.span layoutId={reduce ? undefined : `${uid}-tab`} className=\"absolute inset-0 rounded-full\" style={{ background: p.buttonBg }} transition={{ type: \"spring\", stiffness: 500, damping: 38 }} />}\n                <span className=\"relative\">{t === \"buy\" ? \"Buy a card\" : \"Check balance\"}</span>\n              </button>\n            ))}\n          </div>\n\n          {tab === \"buy\" ? (\n            <div className=\"mt-6 flex flex-col gap-5\">\n              <fieldset className=\"m-0 border-0 p-0\">\n                <legend className={label}>Amount</legend>\n                <div className=\"flex flex-wrap gap-2\">\n                  {amounts.map((a) => {\n                    const on = !custom && amount === a;\n                    return (\n                      <button\n                        key={a}\n                        type=\"button\"\n                        aria-pressed={on}\n                        onClick={() => {\n                          setAmount(a);\n                          setCustom(\"\");\n                        }}\n                        className={cn(\"h-11 min-w-[72px] cursor-pointer rounded-xl border px-4 text-[14px] font-medium tabular-nums transition-colors\", focus)}\n                        style={{ borderColor: on ? p.title : p.line, background: on ? p.buttonBg : \"transparent\", color: on ? p.buttonText : p.title, ...ring }}\n                      >\n                        {currency}\n                        {a}\n                      </button>\n                    );\n                  })}\n                  <label className=\"flex h-11 min-w-[130px] flex-1 items-center rounded-xl border px-3 focus-within:ring-2\" style={inputStyle(!!amountError)}>\n                    <span style={{ color: p.muted }}>{currency}</span>\n                    <input value={custom} onChange={(e) => setCustom(e.target.value.replace(/\\D/g, \"\").slice(0, 4))} inputMode=\"numeric\" placeholder={`Other (${min}–${max})`} aria-label=\"Custom amount\" className=\"h-full min-w-0 flex-1 border-0 bg-transparent px-1.5 text-[14px] tabular-nums outline-none\" style={{ color: p.title }} />\n                  </label>\n                </div>\n                {amountError && (\n                  <p className=\"m-0 mt-1.5 text-[12px]\" role=\"alert\" style={{ color: p.error }}>\n                    {amountError}\n                  </p>\n                )}\n              </fieldset>\n              <div className=\"grid grid-cols-1 gap-3 @[560px]:grid-cols-2\">\n                <div>\n                  <label htmlFor={`${uid}-to`} className={label}>\n                    Recipient name\n                  </label>\n                  <input id={`${uid}-to`} value={o.to} onChange={(e) => setO((s) => ({ ...s, to: e.target.value.slice(0, 30) }))} placeholder=\"Sam\" className={input} style={inputStyle(touched && !o.to.trim())} />\n                </div>\n                <div>\n                  <label htmlFor={`${uid}-email`} className={label}>\n                    Recipient email\n                  </label>\n                  <input id={`${uid}-email`} type=\"email\" value={o.email} onChange={(e) => setO((s) => ({ ...s, email: e.target.value }))} placeholder=\"sam@example.com\" aria-invalid={(touched && !!emailError) || undefined} className={input} style={inputStyle(touched && !!emailError)} />\n                </div>\n                <div>\n                  <label htmlFor={`${uid}-from`} className={label}>\n                    From\n                  </label>\n                  <input id={`${uid}-from`} value={o.from} onChange={(e) => setO((s) => ({ ...s, from: e.target.value.slice(0, 30) }))} placeholder=\"Your name\" className={input} style={inputStyle()} />\n                </div>\n                <div>\n                  <span className={label} id={`${uid}-when`}>\n                    Send\n                  </span>\n                  <div role=\"radiogroup\" aria-labelledby={`${uid}-when`} className=\"grid h-11 grid-cols-2 rounded-xl border p-1\" style={{ borderColor: p.line }}>\n                    {([\"now\", \"later\"] as const).map((w) => (\n                      <button key={w} type=\"button\" role=\"radio\" aria-checked={o.sendOn === w} onClick={() => setO((s) => ({ ...s, sendOn: w }))} className={cn(\"cursor-pointer rounded-lg border-0 text-[13px] font-medium\", focus)} style={{ background: o.sendOn === w ? p.line : \"transparent\", color: o.sendOn === w ? p.title : p.muted, ...ring }}>\n                        {w === \"now\" ? \"Right away\" : \"On a date\"}\n                      </button>\n                    ))}\n                  </div>\n                </div>\n              </div>\n              <div>\n                <label htmlFor={`${uid}-msg`} className={label}>\n                  Message <span style={{ color: p.muted }}>(optional)</span>\n                </label>\n                <textarea id={`${uid}-msg`} value={o.message} onChange={(e) => setO((s) => ({ ...s, message: e.target.value.slice(0, 140) }))} rows={2} placeholder=\"Happy birthday! Treat yourself.\" className=\"w-full resize-none rounded-xl border px-3.5 py-2.5 text-[14px] outline-none focus-visible:ring-2\" style={inputStyle()} />\n              </div>\n              <button type=\"button\" onClick={add} aria-live=\"polite\" className={cn(\"flex h-12 w-full cursor-pointer items-center justify-center gap-2 rounded-full border-0 text-[15px] font-semibold\", focus)} style={{ background: state === \"added\" ? p.accent : p.buttonBg, color: state === \"added\" ? \"#0A0A0A\" : p.buttonText, opacity: valid || state !== \"idle\" ? 1 : 0.7, transition: \"background-color .25s\", ...ring }}>\n                {state === \"loading\" ? <motion.span className=\"h-4 w-4 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.7, ease: \"linear\" }} aria-label=\"Adding\" /> : state === \"added\" ? \"✓ Gift card added to cart\" : `Add to cart · ${currency}${(value || 0).toFixed(2)}`}\n              </button>\n              {touched && !valid && (\n                <p className=\"m-0 -mt-3 text-center text-[12px]\" role=\"alert\" style={{ color: p.error }}>\n                  {amountError ?? (!o.to.trim() ? \"Add the recipient's name\" : emailError)}\n                </p>\n              )}\n            </div>\n          ) : (\n            <form onSubmit={check} className=\"mt-6 flex flex-col gap-4\">\n              <div>\n                <label htmlFor={`${uid}-code`} className={label}>\n                  Gift card code\n                </label>\n                <div className=\"flex gap-2\">\n                  <input\n                    id={`${uid}-code`}\n                    value={code}\n                    onChange={(e) => {\n                      setCode(e.target.value.toUpperCase().slice(0, 14));\n                      setBalance(null);\n                    }}\n                    placeholder=\"NL-0000-0000\"\n                    className={cn(input, \"font-mono tracking-[0.06em]\")}\n                    style={inputStyle(balance?.ok === false)}\n                  />\n                  <button type=\"submit\" disabled={!code.trim() || checking} className={cn(\"h-11 shrink-0 cursor-pointer rounded-xl border-0 px-5 text-[14px] font-semibold disabled:opacity-40\", focus)} style={{ background: p.buttonBg, color: p.buttonText, ...ring }}>\n                    {checking ? \"Checking…\" : \"Check\"}\n                  </button>\n                </div>\n                <p className=\"m-0 mt-1.5 text-[12px]\" style={{ color: p.muted }}>\n                  Try NL-4821-7730. The code is in the email and on the back of physical cards.\n                </p>\n              </div>\n              <AnimatePresence mode=\"popLayout\" initial={false}>\n                {balance && (\n                  <motion.div key={balance.ok ? \"ok\" : \"no\"} role=\"status\" initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"rounded-2xl border p-5\" style={{ borderColor: balance.ok ? `${p.accent}66` : `${p.error}66`, background: balance.ok ? `${p.accent}12` : `${p.error}10` }}>\n                    {balance.ok ? (\n                      <>\n                        <p className=\"m-0 text-[13px]\" style={{ color: p.body }}>\n                          Remaining balance\n                        </p>\n                        <p className=\"m-0 mt-1 text-[34px] font-semibold tracking-[-0.02em] tabular-nums\">\n                          {currency}\n                          {balance.value!.toFixed(2)}\n                        </p>\n                        <p className=\"m-0 mt-1 text-[12.5px]\" style={{ color: p.muted }}>\n                          Never expires · use it at checkout or in store\n                        </p>\n                      </>\n                    ) : (\n                      <p className=\"m-0 text-[13.5px]\" style={{ color: p.error }}>\n                        We couldn&apos;t find that code. Check it and try again.\n                      </p>\n                    )}\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </form>\n          )}\n        </div>\n      </div>\n    </section>\n  );\n}\n\nexport default GiftCardBlock;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}