{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "banner-10",
  "title": "Sale countdown banner",
  "description": "An offer with the hours, minutes and seconds left until midnight.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/status-orb.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/banner/banner-10.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useState, useSyncExternalStore } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { TicketPercentIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { StatusOrb } from '@/registry/ndeko/ui/status-orb';\n\nconst SECOND_MS = 1000;\nconst SECONDS_PER_MINUTE = 60;\nconst SECONDS_PER_HOUR = 3600;\nconst CLOCK_NOT_STARTED = 0;\nconst EMPTY_DIGITS = '--';\n\nconst COLLAPSE_TRANSITION: Transition = { duration: 0.2, ease: [0.2, 0, 0, 1] };\nconst DISMISS_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.2, 0, 0, 1],\n};\n\nconst COLLAPSE_VARIANTS: Variants = {\n  shown: { height: 'auto', opacity: 1 },\n  hidden: { height: 0, opacity: 0, transition: DISMISS_TRANSITION },\n};\n\nconst FADE_VARIANTS: Variants = {\n  shown: { opacity: 1 },\n  hidden: { opacity: 0, transition: DISMISS_TRANSITION },\n};\n\nlet clockSecond = CLOCK_NOT_STARTED;\n\nfunction collapseVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return COLLAPSE_VARIANTS;\n}\n\nfunction currentSecond() {\n  const now = Date.now();\n  return Math.floor(now / SECOND_MS);\n}\n\nfunction subscribeToClock(onTick: () => void) {\n  function tick() {\n    clockSecond = currentSecond();\n    onTick();\n  }\n  tick();\n  const interval = window.setInterval(tick, SECOND_MS);\n  return () => window.clearInterval(interval);\n}\n\nfunction readClock() {\n  return clockSecond;\n}\n\nfunction readServerClock() {\n  return CLOCK_NOT_STARTED;\n}\n\nfunction secondsUntilMidnight(epochSecond: number) {\n  const midnight = new Date(epochSecond * SECOND_MS);\n  midnight.setHours(24, 0, 0, 0);\n  const midnightMs = midnight.getTime();\n  const midnightSecond = Math.floor(midnightMs / SECOND_MS);\n  return midnightSecond - epochSecond;\n}\n\nfunction twoDigits(value: number) {\n  const text = String(value);\n  return text.padStart(2, '0');\n}\n\nfunction countdownOf(epochSecond: number) {\n  if (epochSecond === CLOCK_NOT_STARTED) {\n    return {\n      hours: EMPTY_DIGITS,\n      minutes: EMPTY_DIGITS,\n      seconds: EMPTY_DIGITS,\n    };\n  }\n  const remaining = secondsUntilMidnight(epochSecond);\n  const hours = Math.floor(remaining / SECONDS_PER_HOUR);\n  const secondsInHour = remaining % SECONDS_PER_HOUR;\n  const minutes = Math.floor(secondsInHour / SECONDS_PER_MINUTE);\n  const seconds = remaining % SECONDS_PER_MINUTE;\n  return {\n    hours: twoDigits(hours),\n    minutes: twoDigits(minutes),\n    seconds: twoDigits(seconds),\n  };\n}\n\nexport default function Banner10() {\n  const [isVisible, setIsVisible] = useState(true);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const collapseVariants = collapseVariantsOf(shouldReduceMotion);\n  const epochSecond = useSyncExternalStore(\n    subscribeToClock,\n    readClock,\n    readServerClock\n  );\n  const countdown = countdownOf(epochSecond);\n\n  function dismiss() {\n    setIsVisible(false);\n  }\n\n  return (\n    <AnimatePresence initial={false}>\n      {isVisible && (\n        <motion.div\n          key='banner'\n          className='bg-primary/[0.06] hairline-ring ring-primary/15 dark:bg-primary/10 @container w-full overflow-hidden rounded-xl'\n          variants={collapseVariants}\n          initial='hidden'\n          animate='shown'\n          exit='hidden'\n          transition={COLLAPSE_TRANSITION}\n        >\n          <div className='flex gap-2 px-4 py-3 @xl:items-center'>\n            <div className='flex grow gap-3 @xl:items-center'>\n              <StatusOrb\n                tone='brand'\n                glyph={<TicketPercentIcon strokeWidth={2.25} />}\n                className='m-1'\n              />\n              <div className='flex grow flex-col justify-between gap-3 @xl:flex-row @xl:items-center'>\n                <div className='flex flex-col gap-0.5 text-[13px]'>\n                  <p className='font-medium'>Spring sale ends at midnight</p>\n                  <p className='text-muted-foreground'>\n                    Annual plans are 30% off until the end of the day.\n                  </p>\n                </div>\n                <div className='flex flex-wrap items-center gap-3'>\n                  <div\n                    role='timer'\n                    className='bg-card hairline-ring ring-border hairline-divide-x divide-border flex h-7 items-center rounded-md text-[13px] tabular-nums'\n                  >\n                    <span className='px-2'>\n                      {countdown.hours}\n                      <span className='text-muted-foreground'>h</span>\n                    </span>\n                    <span className='px-2'>\n                      {countdown.minutes}\n                      <span className='text-muted-foreground'>m</span>\n                    </span>\n                    <span className='px-2'>\n                      {countdown.seconds}\n                      <span className='text-muted-foreground'>s</span>\n                    </span>\n                  </div>\n                  <Button size='sm'>Buy now</Button>\n                </div>\n              </div>\n            </div>\n            <Button\n              variant='ghost'\n              size='icon-sm'\n              className='-me-2 @xl:-my-0.5'\n              aria-label='Dismiss banner'\n              onClick={dismiss}\n            >\n              <XIcon className='opacity-60' />\n            </Button>\n          </div>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "banner"
  ],
  "type": "registry:component"
}