{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "countdown-sale-banner",
  "title": "Countdown Sale Banner",
  "description": "A sale bar that counts down for real: rolling days, hours, minutes and seconds, a coupon that copies with one click, and an ending message when time runs out.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/countdown-sale-banner/countdown-sale-banner.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface CountdownSaleBannerProps extends Omit<\n  React.ComponentPropsWithoutRef<\"div\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  /** Bold lead of the message. */\n  title?: string;\n  message?: string;\n  /** When the sale ends: a date, or an ISO string. Defaults to 2 days 14 hours after the banner appears. */\n  endsAt?: string | number | Date;\n  /** Shown once the time is up. */\n  endedMessage?: string;\n  /** A code people can copy. Pass an empty string to hide it. */\n  code?: string;\n  action?: { label: string; href?: string; onClick?: () => void } | null;\n  dismissible?: boolean;\n  onDismiss?: () => void;\n}\n\nconst PALETTES = {\n  dark: {\n    bar: \"#0F1011\",\n    surface: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.06)\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n    accent: \"#5E6AD2\",\n    shadow: \"0 8px 32px rgba(0,0,0,0.45)\",\n  },\n  light: {\n    bar: \"#FFFFFF\",\n    surface: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n    accent: \"#5E6AD2\",\n    shadow: \"0 8px 28px rgba(8,9,10,0.12)\",\n  },\n};\n\ntype Palette = (typeof PALETTES)[\"dark\"];\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction CloseButton({\n  label,\n  pal,\n  onClick,\n}: {\n  label: string;\n  pal: Palette;\n  onClick: () => void;\n}) {\n  return (\n    <button\n      type=\"button\"\n      aria-label={label}\n      onClick={onClick}\n      className=\"grid size-7 shrink-0 cursor-pointer place-items-center rounded-full transition-colors outline-none hover:bg-[var(--chip)] focus-visible:ring-2\"\n      style={{ \"--chip\": pal.chip, color: pal.sub } as React.CSSProperties}\n    >\n      <svg\n        width=\"10\"\n        height=\"10\"\n        viewBox=\"0 0 10 10\"\n        fill=\"none\"\n        stroke=\"currentColor\"\n        strokeWidth=\"1.6\"\n        strokeLinecap=\"round\"\n        aria-hidden=\"true\"\n      >\n        <path d=\"m1 1 8 8M9 1 1 9\" />\n      </svg>\n    </button>\n  );\n}\n\n/** Folds its content away when closed, so a dismissed bar doesn't leave a gap. */\nfunction Collapse({\n  open,\n  onGone,\n  children,\n}: {\n  open: boolean;\n  onGone?: () => void;\n  children: React.ReactNode;\n}) {\n  return (\n    <div\n      className=\"grid motion-safe:transition-[grid-template-rows,opacity] motion-safe:duration-300\"\n      style={{ gridTemplateRows: open ? \"1fr\" : \"0fr\", opacity: open ? 1 : 0 }}\n      onTransitionEnd={(e) => {\n        if (!open && e.propertyName === \"grid-template-rows\") onGone?.();\n      }}\n    >\n      <div className=\"min-h-0 overflow-hidden\">{children}</div>\n    </div>\n  );\n}\n\nconst DEFAULT_SPAN = (2 * 24 + 14) * 3600 * 1000 + 37 * 60 * 1000;\n\n/** A digit pair that rolls in from below each time it changes. */\nfunction Unit({\n  value,\n  label,\n  pal,\n  still,\n}: {\n  value: number | null;\n  label: string;\n  pal: Palette;\n  still: boolean;\n}) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  React.useEffect(() => {\n    if (still || value === null) return;\n    ref.current?.animate(\n      [\n        { transform: \"translateY(55%)\", opacity: 0 },\n        { transform: \"translateY(0)\", opacity: 1 },\n      ],\n      { duration: 260, easing: \"cubic-bezier(0.22,1,0.36,1)\" },\n    );\n  }, [value, still]);\n  return (\n    <span\n      className=\"flex h-8 min-w-[44px] items-baseline justify-center gap-0.5 overflow-hidden rounded-md px-1.5 pt-[7px]\"\n      style={{ background: pal.chip }}\n    >\n      <span\n        ref={ref}\n        className=\"inline-block text-[14px] leading-none font-[510] tabular-nums\"\n      >\n        {value === null ? \"--\" : String(value).padStart(2, \"0\")}\n      </span>\n      <span className=\"text-[11px] leading-none\" style={{ color: pal.sub }}>\n        {label}\n      </span>\n    </span>\n  );\n}\n\nexport function CountdownSaleBanner({\n  theme = \"dark\",\n  title = \"Winter sale\",\n  message = \"40% off every annual plan.\",\n  endsAt,\n  endedMessage = \"The sale has ended.\",\n  code = \"WINTER40\",\n  action = { label: \"Claim offer\" },\n  dismissible = true,\n  onDismiss,\n  className,\n  style,\n  ...props\n}: CountdownSaleBannerProps) {\n  const pal = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const [left, setLeft] = React.useState<number | null>(null);\n  const [copied, setCopied] = React.useState(false);\n  const [open, setOpen] = React.useState(true);\n  const copiedTimer = React.useRef(0);\n  const target = endsAt ? new Date(endsAt).getTime() : null;\n\n  // The clock only starts in the browser, so the server and first render agree.\n  React.useEffect(() => {\n    const end = target ?? Date.now() + DEFAULT_SPAN;\n    const tick = () => setLeft(Math.max(0, end - Date.now()));\n    const first = window.setTimeout(tick, 0);\n    const timer = window.setInterval(tick, 1000);\n    return () => {\n      window.clearTimeout(first);\n      window.clearInterval(timer);\n    };\n  }, [target]);\n\n  React.useEffect(() => () => window.clearTimeout(copiedTimer.current), []);\n\n  const copy = async () => {\n    try {\n      await navigator.clipboard?.writeText(code);\n    } catch {\n      // Still confirm: people can read the code off the button.\n    }\n    setCopied(true);\n    window.clearTimeout(copiedTimer.current);\n    copiedTimer.current = window.setTimeout(() => setCopied(false), 1600);\n  };\n\n  const ended = left === 0;\n  const seconds = left === null ? null : Math.floor(left / 1000);\n  const part = (size: number, wrap: number) =>\n    seconds === null ? null : Math.floor(seconds / size) % wrap;\n\n  return (\n    <Collapse open={open} onGone={onDismiss}>\n      <div\n        role=\"region\"\n        aria-label={title}\n        className={`@container w-full ${className ?? \"\"}`}\n        style={{\n          background: pal.bar,\n          boxShadow: `inset 0 -1px 0 ${pal.border}`,\n          color: pal.text,\n          fontFamily: FONT,\n          ...style,\n        }}\n        {...props}\n      >\n        <div className=\"flex flex-wrap items-center justify-center gap-x-4 gap-y-2 px-4 py-2.5\">\n          <p className=\"m-0 text-[13px] tracking-[-0.011em]\">\n            <span className=\"font-[590]\">{title}.</span>{\" \"}\n            <span style={{ color: pal.sub }}>\n              {ended ? endedMessage : message}\n            </span>\n          </p>\n          {!ended && (\n            <>\n              <div\n                role=\"timer\"\n                aria-label=\"Time left\"\n                className=\"flex items-center gap-1\"\n              >\n                <Unit\n                  value={part(86400, 1000)}\n                  label=\"d\"\n                  pal={pal}\n                  still={reduce}\n                />\n                <Unit\n                  value={part(3600, 24)}\n                  label=\"h\"\n                  pal={pal}\n                  still={reduce}\n                />\n                <Unit value={part(60, 60)} label=\"m\" pal={pal} still={reduce} />\n                <Unit value={part(1, 60)} label=\"s\" pal={pal} still={reduce} />\n              </div>\n              {code && (\n                <button\n                  type=\"button\"\n                  onClick={copy}\n                  aria-label={`Copy code ${code}`}\n                  className=\"flex h-8 min-w-[108px] cursor-pointer items-center justify-center gap-1.5 rounded-md border border-dashed px-2.5 font-mono text-[12px] outline-none focus-visible:ring-2\"\n                  style={{ borderColor: pal.faint, color: pal.soft }}\n                >\n                  {copied ? \"Copied\" : code}\n                </button>\n              )}\n              {action &&\n                (action.href ? (\n                  <a\n                    href={action.href}\n                    className=\"inline-flex h-8 items-center rounded-full px-3.5 text-[13px] font-[510] no-underline transition-opacity hover:opacity-90\"\n                    style={{ background: pal.btn, color: pal.btnText }}\n                  >\n                    {action.label}\n                  </a>\n                ) : (\n                  <button\n                    type=\"button\"\n                    onClick={action.onClick}\n                    className=\"h-8 cursor-pointer rounded-full px-3.5 text-[13px] font-[510] transition-opacity hover:opacity-90\"\n                    style={{ background: pal.btn, color: pal.btnText }}\n                  >\n                    {action.label}\n                  </button>\n                ))}\n            </>\n          )}\n          {dismissible && (\n            <CloseButton\n              label=\"Dismiss\"\n              pal={pal}\n              onClick={() => setOpen(false)}\n            />\n          )}\n        </div>\n      </div>\n    </Collapse>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}