{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popup-promo-countdown",
  "type": "registry:component",
  "title": "Promo Countdown Popup",
  "description": "A limited-time offer inside a rotating light border, with rolling digit reels for the countdown, a striped claimed-seats bar and a CTA with a sheen. It switches to an ended state when the timer reaches zero.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "modals",
    "promo",
    "countdown",
    "sale",
    "popup",
    "urgency",
    "pricing"
  ],
  "docs": "https://hyperblur.dev/effects/popup-promo-countdown",
  "files": [
    {
      "path": "registry/hyperblur/popup-promo-countdown.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/popup-promo-countdown.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PopupPromoCountdownProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  eyebrow?: string;\n  title?: string;\n  description?: string;\n  discount?: number;\n  duration?: number;\n  endsAt?: string;\n  claimed?: number;\n  total?: number;\n  ctaLabel?: string;\n  onClaim?: () => void;\n  onExpire?: () => void;\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  showTrigger?: boolean;\n  triggerLabel?: string;\n  embedded?: boolean;\n  accent?: string;\n}\n\nconst focusable = 'a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])';\n\nfunction useModal(active: boolean, panelRef: React.RefObject<HTMLElement | null>, onClose: () => void) {\n  const closeRef = React.useRef(onClose);\n  React.useEffect(() => {\n    closeRef.current = onClose;\n  });\n  React.useEffect(() => {\n    if (!active) return;\n    const panel = panelRef.current;\n    if (!panel) return;\n    const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;\n    const html = document.documentElement;\n    const prevOverflow = html.style.overflow;\n    html.style.overflow = \"hidden\";\n    (panel.querySelector<HTMLElement>(\"[data-autofocus]\") ?? panel).focus({ preventScroll: true });\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        closeRef.current();\n        return;\n      }\n      if (e.key !== \"Tab\") return;\n      const nodes = Array.from(panel.querySelectorAll<HTMLElement>(focusable)).filter((n) => n.getClientRects().length > 0);\n      if (!nodes.length) {\n        e.preventDefault();\n        return;\n      }\n      const first = nodes[0];\n      const last = nodes[nodes.length - 1];\n      const cur = document.activeElement;\n      if (e.shiftKey && (cur === first || cur === panel || !panel.contains(cur))) {\n        e.preventDefault();\n        last.focus();\n      } else if (!e.shiftKey && (cur === last || !panel.contains(cur))) {\n        e.preventDefault();\n        first.focus();\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"keydown\", onKey);\n      html.style.overflow = prevOverflow;\n      opener?.focus({ preventScroll: true });\n    };\n  }, [active, panelRef]);\n}\n\nfunction usePresence(open: boolean, ms: number) {\n  const [mounted, setMounted] = React.useState(open);\n  if (open && !mounted) setMounted(true);\n  React.useEffect(() => {\n    if (open || !mounted) return;\n    const t = window.setTimeout(() => setMounted(false), ms);\n    return () => window.clearTimeout(t);\n  }, [open, mounted, ms]);\n  return mounted;\n}\n\nconst css = `\n.hb-xf6 { --hb-xf6-accent: #ffcc33; box-sizing: border-box; font-family: inherit; color: #ededed; }\n.hb-xf6 *, .hb-xf6 *::before, .hb-xf6 *::after { box-sizing: border-box; }\n@property --hb-xf6-spin { syntax: \"<angle>\"; inherits: false; initial-value: 0deg; }\n.hb-xf6-embedded { position: relative; width: 100%; height: 100%; display: grid; place-items: center; }\n.hb-xf6-trigger { all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px 0 8px; border-radius: 999px; font-size: 13px; font-weight: 600; color: #0a0a0a; background: var(--hb-xf6-accent); box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 8px 20px -10px var(--hb-xf6-accent); cursor: pointer; transition: transform .15s cubic-bezier(.3,.7,.4,1), filter .2s; }\n.hb-xf6-trigger:hover { filter: brightness(1.06); }\n.hb-xf6-trigger:active { transform: scale(.97); }\n.hb-xf6-trigger:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-xf6-trigger span { display: grid; place-items: center; height: 22px; padding: 0 7px; border-radius: 999px; background: #0a0a0a; color: var(--hb-xf6-accent); font-size: 11px; }\n.hb-xf6-overlay { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 16px; min-height: 100dvh; }\n.hb-xf6-embedded .hb-xf6-overlay { position: relative; inset: auto; min-height: 0; padding: 0; width: 100%; }\n.hb-xf6-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.78); backdrop-filter: blur(5px); animation: hb-xf6-fade .3s ease both; }\n.hb-xf6-embedded .hb-xf6-scrim { display: none; }\n.hb-xf6-overlay[data-state=\"closed\"] .hb-xf6-scrim { animation: hb-xf6-fade .2s ease reverse both; }\n.hb-xf6-frame { position: relative; width: min(400px, 100%); max-height: calc(100dvh - 32px); padding: 1px; border-radius: 24px; background: conic-gradient(from var(--hb-xf6-spin), transparent 0 60%, var(--hb-xf6-accent) 78%, #fff 82%, transparent 88% 100%), #2a2a2a; animation: hb-xf6-in .55s cubic-bezier(.16,1,.3,1) both, hb-xf6-rot 4s linear infinite; box-shadow: 0 40px 90px -30px rgba(0,0,0,.95); }\n.hb-xf6-overlay[data-state=\"closed\"] .hb-xf6-frame { animation: hb-xf6-out .2s cubic-bezier(.4,0,1,1) both; }\n.hb-xf6-panel { position: relative; max-height: calc(100dvh - 34px); overflow: auto; border-radius: 23px; padding: 22px 22px 18px; background: radial-gradient(120% 60% at 50% 0%, color-mix(in srgb, var(--hb-xf6-accent) 14%, #121212), #0f0f0f 70%); outline: none; text-align: center; }\n.hb-xf6-close { all: unset; position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: #8f8f8f; cursor: pointer; transition: background .2s, color .2s; }\n.hb-xf6-close:hover { background: #1f1f1f; color: #ededed; }\n.hb-xf6-close:focus-visible { outline: 2px solid var(--hb-xf6-accent); }\n.hb-xf6-close svg { width: 14px; height: 14px; }\n.hb-xf6-eyebrow { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-family: var(--font-mono), ui-monospace, monospace; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--hb-xf6-accent); background: color-mix(in srgb, var(--hb-xf6-accent) 10%, transparent); border: 1px solid color-mix(in srgb, var(--hb-xf6-accent) 25%, transparent); }\n.hb-xf6-eyebrow i { font-style: normal; width: 6px; height: 6px; border-radius: 50%; background: var(--hb-xf6-accent); animation: hb-xf6-blink 1.2s steps(2, jump-none) infinite; }\n.hb-xf6-big { margin: 12px 0 2px; font-family: var(--font-grotesk), var(--font-sans), sans-serif; font-size: 64px; line-height: .9; font-weight: 700; letter-spacing: -.05em; background: linear-gradient(180deg, #fff 30%, color-mix(in srgb, var(--hb-xf6-accent) 80%, #fff)); -webkit-background-clip: text; background-clip: text; color: transparent; }\n.hb-xf6-big small { font-size: 26px; letter-spacing: -.02em; margin-left: 4px; }\n.hb-xf6-title { margin: 6px 0 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }\n.hb-xf6-desc { margin: 4px auto 0; max-width: 300px; font-size: 12.5px; line-height: 1.5; color: #a1a1a1; }\n.hb-xf6-clock { display: flex; justify-content: center; align-items: flex-start; gap: 6px; margin: 16px 0 14px; }\n.hb-xf6-unit { display: grid; gap: 5px; justify-items: center; }\n.hb-xf6-digits { display: flex; gap: 2px; }\n.hb-xf6-digit { position: relative; width: 26px; height: 38px; overflow: hidden; border-radius: 8px; background: linear-gradient(#1c1c1c, #141414); border: 1px solid #2a2a2a; box-shadow: inset 0 1px 0 rgba(255,255,255,.05), 0 4px 10px -6px rgba(0,0,0,.8); }\n.hb-xf6-digit::after { content: \"\"; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: rgba(0,0,0,.55); }\n.hb-xf6-reel { position: absolute; left: 0; right: 0; top: 0; display: flex; flex-direction: column; transform: translateY(calc(var(--hb-xf6-d) * -38px)); transition: transform .6s cubic-bezier(.5,1.6,.4,1); }\n.hb-xf6-reel span { display: grid; place-items: center; height: 38px; font-family: var(--font-mono), ui-monospace, monospace; font-size: 20px; font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }\n.hb-xf6-label { font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: #6f6f6f; }\n.hb-xf6-colon { height: 38px; display: grid; place-items: center; font-size: 18px; color: #555; font-family: var(--font-mono), ui-monospace, monospace; }\n.hb-xf6-stock { display: grid; gap: 6px; margin-bottom: 16px; text-align: left; }\n.hb-xf6-stocktext { display: flex; justify-content: space-between; font-size: 11.5px; color: #a1a1a1; font-variant-numeric: tabular-nums; }\n.hb-xf6-stocktext b { color: #ededed; font-weight: 600; }\n.hb-xf6-bar { position: relative; height: 8px; border-radius: 999px; background: #1c1c1c; box-shadow: inset 0 1px 2px rgba(0,0,0,.6); overflow: hidden; }\n.hb-xf6-fill { position: absolute; inset: 0 auto 0 0; width: var(--hb-xf6-pct); border-radius: inherit; background: linear-gradient(90deg, color-mix(in srgb, var(--hb-xf6-accent) 60%, #000), var(--hb-xf6-accent)); animation: hb-xf6-grow 1.1s cubic-bezier(.2,.8,.2,1) .25s both; transition: width .6s cubic-bezier(.3,.7,.4,1); }\n.hb-xf6-fill::after { content: \"\"; position: absolute; inset: 0; background: repeating-linear-gradient(-45deg, rgba(255,255,255,.18) 0 4px, transparent 4px 9px); background-size: 26px 100%; animation: hb-xf6-stripes .9s linear infinite; }\n.hb-xf6-cta { all: unset; box-sizing: border-box; position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 44px; border-radius: 13px; overflow: hidden; font-size: 14px; font-weight: 700; color: #0a0a0a; background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xf6-accent) 70%, #fff), var(--hb-xf6-accent)); box-shadow: inset 0 1px 0 rgba(255,255,255,.6), inset 0 -2px 0 rgba(0,0,0,.15), 0 12px 28px -12px var(--hb-xf6-accent); cursor: pointer; transition: transform .15s cubic-bezier(.3,.7,.4,1), filter .2s; }\n.hb-xf6-cta::before { content: \"\"; position: absolute; top: 0; bottom: 0; left: -40%; width: 30%; background: linear-gradient(100deg, transparent, rgba(255,255,255,.65), transparent); transform: skewX(-20deg); animation: hb-xf6-sheen 3.2s cubic-bezier(.4,0,.2,1) 1s infinite; }\n.hb-xf6-cta:hover { filter: brightness(1.05); }\n.hb-xf6-cta:active { transform: scale(.98); }\n.hb-xf6-cta:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-xf6-cta:disabled { cursor: not-allowed; color: #6f6f6f; background: #1c1c1c; box-shadow: inset 0 0 0 1px #2a2a2a; }\n.hb-xf6-cta:disabled::before { display: none; }\n.hb-xf6-fine { margin: 10px 0 0; font-size: 11px; color: #6f6f6f; }\n.hb-xf6[data-urgent=\"true\"] .hb-xf6-digit { border-color: color-mix(in srgb, #ff5d5d 50%, #2a2a2a); }\n@keyframes hb-xf6-fade { from { opacity: 0; } }\n@keyframes hb-xf6-in { from { opacity: 0; transform: scale(.9) rotate(-1.5deg); } }\n@keyframes hb-xf6-out { to { opacity: 0; transform: scale(.96); } }\n@keyframes hb-xf6-rot { to { --hb-xf6-spin: 360deg; } }\n@keyframes hb-xf6-blink { 50% { opacity: .2; } }\n@keyframes hb-xf6-grow { from { width: 0; } }\n@keyframes hb-xf6-stripes { to { background-position: 26px 0; } }\n@keyframes hb-xf6-sheen { 0% { left: -40%; } 45%, 100% { left: 130%; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xf6 *, .hb-xf6 *::before, .hb-xf6 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction Digit({ value }: { value: number }) {\n  return (\n    <span className=\"hb-xf6-digit\" aria-hidden=\"true\">\n      <span className=\"hb-xf6-reel\" style={{ \"--hb-xf6-d\": value } as React.CSSProperties}>\n        {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((n) => (\n          <span key={n}>{n}</span>\n        ))}\n      </span>\n    </span>\n  );\n}\n\nfunction Unit({ value, label }: { value: number; label: string }) {\n  const v = Math.min(99, Math.max(0, value));\n  return (\n    <span className=\"hb-xf6-unit\">\n      <span className=\"hb-xf6-digits\">\n        <Digit value={Math.floor(v / 10)} />\n        <Digit value={v % 10} />\n      </span>\n      <span className=\"hb-xf6-label\">{label}</span>\n    </span>\n  );\n}\n\nexport function PopupPromoCountdown({\n  eyebrow = \"Black Friday\",\n  title = \"Pro, annual plan\",\n  description = \"Every template, the Figma kit and priority support. Locked at this price for as long as you stay.\",\n  discount = 40,\n  duration = 8049,\n  endsAt,\n  claimed = 812,\n  total = 1000,\n  ctaLabel,\n  onClaim,\n  onExpire,\n  open,\n  defaultOpen,\n  onOpenChange,\n  showTrigger = true,\n  triggerLabel = \"See the deal\",\n  embedded = false,\n  accent = \"#ffcc33\",\n  className = \"\",\n  style,\n  ...rest\n}: PopupPromoCountdownProps) {\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const [inner, setInner] = React.useState(defaultOpen ?? embedded);\n  const isOpen = open ?? inner;\n  const mounted = usePresence(isOpen, 220);\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const triggerRef = React.useRef<HTMLButtonElement>(null);\n  const touched = React.useRef(false);\n  const [left, setLeft] = React.useState(Math.max(0, Math.floor(duration)));\n  const [taken, setTaken] = React.useState(claimed);\n  const expireRef = React.useRef(onExpire);\n\n  React.useEffect(() => {\n    expireRef.current = onExpire;\n  });\n\n  const setOpen = React.useCallback(\n    (value: boolean) => {\n      touched.current = true;\n      if (open === undefined) setInner(value);\n      onOpenChange?.(value);\n    },\n    [open, onOpenChange],\n  );\n  const close = React.useCallback(() => setOpen(false), [setOpen]);\n  useModal(isOpen && !embedded, panelRef, close);\n\n  React.useEffect(() => {\n    if (!embedded || !touched.current) return;\n    if (isOpen) panelRef.current?.focus({ preventScroll: true });\n    else triggerRef.current?.focus({ preventScroll: true });\n  }, [embedded, isOpen]);\n\n  React.useEffect(() => {\n    const end = endsAt ? Date.parse(endsAt) : Date.now() + Math.max(0, Math.floor(duration)) * 1000;\n    let done = false;\n    const tick = () => {\n      const s = Math.max(0, Math.round((end - Date.now()) / 1000));\n      setLeft(s);\n      if (s === 0 && !done) {\n        done = true;\n        expireRef.current?.();\n      }\n    };\n    const first = window.setTimeout(tick, 0);\n    const id = window.setInterval(tick, 1000);\n    return () => {\n      window.clearTimeout(first);\n      window.clearInterval(id);\n    };\n  }, [endsAt, duration]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    const id = window.setInterval(() => setTaken((t) => Math.min(total - 1, t + 1)), 9000);\n    return () => window.clearInterval(id);\n  }, [isOpen, total]);\n\n  const expired = left === 0;\n  const h = Math.floor(left / 3600);\n  const m = Math.floor((left % 3600) / 60);\n  const s = left % 60;\n  const pct = Math.min(100, (taken / Math.max(1, total)) * 100);\n  const spoken = `${h} hours ${m} minutes left`;\n\n  return (\n    <div\n      className={`hb-xf6 ${embedded ? \"hb-xf6-embedded\" : \"\"} ${className}`}\n      data-urgent={left > 0 && left < 600}\n      style={{ \"--hb-xf6-accent\": accent, ...style } as React.CSSProperties}\n      onKeyDown={(e) => {\n        if (embedded && e.key === \"Escape\" && isOpen) {\n          e.stopPropagation();\n          close();\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-popup-promo-countdown\" precedence=\"default\">{css}</style>\n      {showTrigger && (!embedded || !mounted) && (\n        <button ref={triggerRef} type=\"button\" className=\"hb-xf6-trigger\" aria-haspopup=\"dialog\" onClick={() => setOpen(true)}>\n          <span>-{discount}%</span>\n          {triggerLabel}\n        </button>\n      )}\n      {mounted && (\n        <div className=\"hb-xf6-overlay\" data-state={isOpen ? \"open\" : \"closed\"}>\n          <div className=\"hb-xf6-scrim\" onClick={close} aria-hidden=\"true\" />\n          <div className=\"hb-xf6-frame\">\n            <div ref={panelRef} className=\"hb-xf6-panel\" role=\"dialog\" aria-modal={embedded ? undefined : true} aria-labelledby={`${uid}-t`} aria-describedby={`${uid}-d`} tabIndex={-1}>\n              <button type=\"button\" className=\"hb-xf6-close\" aria-label=\"Close\" onClick={close}>\n                <svg viewBox=\"0 0 14 14\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\"><path d=\"m3 3 8 8M11 3l-8 8\" /></svg>\n              </button>\n              <span className=\"hb-xf6-eyebrow\"><i aria-hidden=\"true\" />{eyebrow}</span>\n              <p className=\"hb-xf6-big\" aria-hidden=\"true\">{discount}%<small>off</small></p>\n              <h2 className=\"hb-xf6-title\" id={`${uid}-t`}>{expired ? \"This deal has ended\" : `${discount}% off ${title}`}</h2>\n              <p className=\"hb-xf6-desc\" id={`${uid}-d`}>{description}</p>\n              <div className=\"hb-xf6-clock\" role=\"timer\" aria-label={expired ? \"Offer ended\" : spoken}>\n                <Unit value={h} label=\"Hours\" />\n                <span className=\"hb-xf6-colon\" aria-hidden=\"true\">:</span>\n                <Unit value={m} label=\"Min\" />\n                <span className=\"hb-xf6-colon\" aria-hidden=\"true\">:</span>\n                <Unit value={s} label=\"Sec\" />\n              </div>\n              <div className=\"hb-xf6-stock\">\n                <div className=\"hb-xf6-stocktext\">\n                  <span><b>{taken.toLocaleString(\"en-US\")}</b> of {total.toLocaleString(\"en-US\")} claimed</span>\n                  <span>{(total - taken).toLocaleString(\"en-US\")} left</span>\n                </div>\n                <div className=\"hb-xf6-bar\" role=\"progressbar\" aria-label=\"Seats claimed\" aria-valuemin={0} aria-valuemax={total} aria-valuenow={taken}>\n                  <span className=\"hb-xf6-fill\" style={{ \"--hb-xf6-pct\": `${pct.toFixed(1)}%` } as React.CSSProperties} />\n                </div>\n              </div>\n              <button\n                type=\"button\"\n                className=\"hb-xf6-cta\"\n                data-autofocus\n                disabled={expired}\n                onClick={() => {\n                  onClaim?.();\n                  close();\n                }}\n              >\n                {expired ? \"Offer expired\" : ctaLabel ?? `Claim ${discount}% off`}\n              </button>\n              <p className=\"hb-xf6-fine\">Applied at checkout. Cancel anytime.</p>\n            </div>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}