{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "open-now-badge",
  "type": "registry:component",
  "title": "Open Now Badge",
  "description": "A status pill that reads a weekly schedule and shows Open now, Closing soon, Opening at or Closed today, with overnight ranges, holidays and time zones. Ships a pure getOpenStatus helper.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "ordering",
    "hours",
    "status",
    "badge",
    "open-now",
    "schedule",
    "timezone"
  ],
  "docs": "https://hyperblur.dev/effects/open-now-badge",
  "files": [
    {
      "path": "registry/hyperblur/open-now-badge.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/open-now-badge.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface OpenNowHours {\n  day: number;\n  open: string;\n  close: string;\n}\n\nexport type OpenNowStatus = \"unknown\" | \"open\" | \"closing-soon\" | \"opening-later\" | \"closed\" | \"closed-today\";\n\nexport interface OpenNowResult {\n  status: OpenNowStatus;\n  closesAt?: string;\n  opensAt?: string;\n  opensDay?: number;\n  opensInDays?: number;\n  minutesUntilClose?: number;\n  minutesUntilOpen?: number;\n}\n\nexport interface OpenNowOptions {\n  timeZone?: string;\n  closedDates?: string[];\n  soonMinutes?: number;\n}\n\nexport interface OpenNowBadgeLabels {\n  checking: string;\n  open: string;\n  openShort: string;\n  until: string;\n  closingSoon: string;\n  openingAt: string;\n  opensShort: string;\n  closed: string;\n  closedToday: string;\n  opens: string;\n  tomorrow: string;\n  am: string;\n  pm: string;\n  days: string[];\n}\n\nexport interface OpenNowBadgeProps extends Omit<React.HTMLAttributes<HTMLSpanElement>, \"children\"> {\n  hours?: OpenNowHours[];\n  closedDates?: string[];\n  timeZone?: string;\n  now?: Date | string;\n  soonMinutes?: number;\n  hourCycle?: 12 | 24;\n  size?: \"sm\" | \"md\" | \"lg\";\n  variant?: \"soft\" | \"outline\" | \"solid\";\n  appearance?: \"dark\" | \"light\";\n  compact?: boolean;\n  accent?: string;\n  labels?: Partial<OpenNowBadgeLabels>;\n  onStatusChange?: (status: OpenNowStatus, result: OpenNowResult) => void;\n}\n\nconst defaultLabels: OpenNowBadgeLabels = {\n  checking: \"Checking hours\",\n  open: \"Open now\",\n  openShort: \"Open\",\n  until: \"until {time}\",\n  closingSoon: \"Closing soon\",\n  openingAt: \"Opening at {time}\",\n  opensShort: \"Opens {time}\",\n  closed: \"Closed\",\n  closedToday: \"Closed today\",\n  opens: \"opens {day} {time}\",\n  tomorrow: \"tomorrow\",\n  am: \"am\",\n  pm: \"pm\",\n  days: [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"],\n};\n\nconst defaultHours: OpenNowHours[] = [\n  { day: 0, open: \"10:00\", close: \"21:00\" },\n  { day: 2, open: \"11:00\", close: \"22:00\" },\n  { day: 3, open: \"11:00\", close: \"22:00\" },\n  { day: 4, open: \"11:00\", close: \"22:00\" },\n  { day: 5, open: \"11:00\", close: \"01:00\" },\n  { day: 6, open: \"10:00\", close: \"15:00\" },\n  { day: 6, open: \"17:30\", close: \"01:00\" },\n];\n\nfunction parseTime(value: string) {\n  const match = /^(\\d{1,2}):(\\d{2})$/.exec(value.trim());\n  if (!match) return null;\n  const h = Number(match[1]);\n  const m = Number(match[2]);\n  if (h > 24 || m > 59) return null;\n  return h * 60 + m;\n}\n\nfunction toClock(minutes: number) {\n  const m = ((minutes % 1440) + 1440) % 1440;\n  return `${String(Math.floor(m / 60)).padStart(2, \"0\")}:${String(m % 60).padStart(2, \"0\")}`;\n}\n\nfunction wallClock(date: Date, timeZone?: string) {\n  if (!timeZone) {\n    return { y: date.getFullYear(), mo: date.getMonth() + 1, d: date.getDate(), minutes: date.getHours() * 60 + date.getMinutes() };\n  }\n  const parts = new Intl.DateTimeFormat(\"en-US\", {\n    timeZone,\n    year: \"numeric\",\n    month: \"numeric\",\n    day: \"numeric\",\n    hour: \"numeric\",\n    minute: \"numeric\",\n    hourCycle: \"h23\",\n  }).formatToParts(date);\n  const get = (type: string) => Number(parts.find((p) => p.type === type)?.value ?? 0);\n  return { y: get(\"year\"), mo: get(\"month\"), d: get(\"day\"), minutes: (get(\"hour\") % 24) * 60 + get(\"minute\") };\n}\n\nexport function getOpenStatus(hours: OpenNowHours[], now: Date | string, options: OpenNowOptions = {}): OpenNowResult {\n  const date = typeof now === \"string\" ? new Date(now) : now;\n  if (Number.isNaN(date.getTime())) return { status: \"unknown\" };\n  const soon = options.soonMinutes ?? 30;\n  const { y, mo, d, minutes } = wallClock(date, options.timeZone);\n  const weekday = new Date(Date.UTC(y, mo - 1, d)).getUTCDay();\n  const closed = new Set(options.closedDates ?? []);\n  const dateKey = (offset: number) => new Date(Date.UTC(y, mo - 1, d + offset)).toISOString().slice(0, 10);\n  const ranges: { start: number; end: number; offset: number }[] = [];\n  for (let week = -1; week <= 2; week++) {\n    for (const h of hours) {\n      const open = parseTime(h.open);\n      const rawClose = parseTime(h.close);\n      if (open === null || rawClose === null) continue;\n      const close = rawClose <= open ? rawClose + 1440 : rawClose;\n      const offset = week * 7 + (((h.day % 7) + 7) % 7) - weekday;\n      if (offset < -7 || offset > 14 || closed.has(dateKey(offset))) continue;\n      ranges.push({ start: offset * 1440 + open, end: offset * 1440 + close, offset });\n    }\n  }\n  ranges.sort((a, b) => a.start - b.start);\n  const merged: typeof ranges = [];\n  for (const r of ranges) {\n    const last = merged[merged.length - 1];\n    if (last && r.start <= last.end) last.end = Math.max(last.end, r.end);\n    else merged.push({ ...r });\n  }\n  const current = merged.find((r) => r.start <= minutes && minutes < r.end);\n  if (current) {\n    const left = current.end - minutes;\n    return { status: left <= soon ? \"closing-soon\" : \"open\", closesAt: toClock(current.end), minutesUntilClose: left };\n  }\n  const next = merged.find((r) => r.start > minutes);\n  const nextInfo = next\n    ? {\n        opensAt: toClock(next.start),\n        opensInDays: Math.floor(next.start / 1440),\n        opensDay: (((weekday + Math.floor(next.start / 1440)) % 7) + 7) % 7,\n        minutesUntilOpen: next.start - minutes,\n      }\n    : {};\n  if (next && next.start < 1440) return { status: \"opening-later\", ...nextInfo };\n  const hasToday = !closed.has(dateKey(0)) && hours.some((h) => ((h.day % 7) + 7) % 7 === weekday);\n  return { status: hasToday ? \"closed\" : \"closed-today\", ...nextInfo };\n}\n\nconst css = `\n.hb-oa3 {\n  --hb-oa3-c: #737373;\n  --hb-oa3-text: #ededed;\n  --hb-oa3-h: 30px;\n  --hb-oa3-fs: 13px;\n  --hb-oa3-dot: 7px;\n  --hb-oa3-px: 12px;\n  box-sizing: border-box;\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  max-width: 100%;\n  height: var(--hb-oa3-h);\n  padding: 0 var(--hb-oa3-px) 0 calc(var(--hb-oa3-px) - 1px);\n  border: 1px solid color-mix(in srgb, var(--hb-oa3-c) 30%, transparent);\n  border-radius: 999px;\n  background: color-mix(in srgb, var(--hb-oa3-c) 13%, transparent);\n  color: color-mix(in srgb, var(--hb-oa3-c) 70%, var(--hb-oa3-text));\n  font-family: inherit;\n  font-size: var(--hb-oa3-fs);\n  font-weight: 500;\n  line-height: 1;\n  white-space: nowrap;\n  font-variant-numeric: tabular-nums;\n  transition: background 0.4s ease, border-color 0.4s ease, color 0.4s ease;\n}\n.hb-oa3 *, .hb-oa3 *::before, .hb-oa3 *::after { box-sizing: border-box; }\n.hb-oa3[data-appearance=\"light\"] { --hb-oa3-text: #16130f; color: color-mix(in srgb, var(--hb-oa3-c) 62%, #16130f); }\n.hb-oa3[data-size=\"sm\"] { --hb-oa3-h: 24px; --hb-oa3-fs: 12px; --hb-oa3-dot: 6px; --hb-oa3-px: 9px; gap: 6px; }\n.hb-oa3[data-size=\"lg\"] { --hb-oa3-h: 38px; --hb-oa3-fs: 14.5px; --hb-oa3-dot: 8px; --hb-oa3-px: 15px; gap: 10px; }\n.hb-oa3[data-variant=\"outline\"] { background: transparent; border-color: color-mix(in srgb, var(--hb-oa3-c) 55%, transparent); color: var(--hb-oa3-text); }\n.hb-oa3[data-variant=\"solid\"] { background: var(--hb-oa3-c); border-color: transparent; color: #0a0a0a; }\n.hb-oa3[data-status=\"open\"] { --hb-oa3-c: #22c55e; }\n.hb-oa3[data-status=\"closing-soon\"] { --hb-oa3-c: #f59e0b; }\n.hb-oa3[data-status=\"opening-later\"] { --hb-oa3-c: var(--hb-oa3-accent, #7fb3ff); }\n.hb-oa3[data-status=\"closed\"], .hb-oa3[data-status=\"closed-today\"] { --hb-oa3-c: #f87171; }\n.hb-oa3-dot { position: relative; flex: none; width: var(--hb-oa3-dot); height: var(--hb-oa3-dot); border-radius: 50%; background: var(--hb-oa3-c); }\n.hb-oa3[data-variant=\"solid\"] .hb-oa3-dot { background: #0a0a0a; }\n.hb-oa3-dot::after { content: \"\"; position: absolute; inset: 0; border-radius: 50%; background: inherit; opacity: 0; }\n.hb-oa3[data-status=\"open\"] .hb-oa3-dot::after { animation: hb-oa3-ring 2.4s cubic-bezier(0.2, 0.7, 0.3, 1) infinite; }\n.hb-oa3[data-status=\"closing-soon\"] .hb-oa3-dot::after { animation: hb-oa3-ring 1.2s cubic-bezier(0.2, 0.7, 0.3, 1) infinite; }\n.hb-oa3[data-status=\"closing-soon\"] .hb-oa3-dot { animation: hb-oa3-blink 1.2s ease-in-out infinite; }\n.hb-oa3[data-status=\"unknown\"] .hb-oa3-dot { animation: hb-oa3-blink 1.4s ease-in-out infinite; }\n.hb-oa3-main { font-weight: 600; }\n.hb-oa3-sep { opacity: 0.45; }\n.hb-oa3-detail { min-width: 0; overflow: hidden; text-overflow: ellipsis; opacity: 0.82; }\n.hb-oa3[data-variant=\"outline\"] .hb-oa3-main { color: color-mix(in srgb, var(--hb-oa3-c) 78%, var(--hb-oa3-text)); }\n.hb-oa3[data-status=\"unknown\"] .hb-oa3-main { font-weight: 500; opacity: 0.7; }\n@keyframes hb-oa3-ring { 0% { opacity: 0.55; transform: scale(1); } 100% { opacity: 0; transform: scale(3.2); } }\n@keyframes hb-oa3-blink { 50% { opacity: 0.45; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-oa3 { transition: none; }\n  .hb-oa3 .hb-oa3-dot, .hb-oa3 .hb-oa3-dot::after { animation: none; }\n}\n`;\n\nconst noopSubscribe = () => () => {};\nconst subscribeClock = (callback: () => void) => {\n  const id = window.setInterval(callback, 15000);\n  return () => window.clearInterval(id);\n};\nconst clockSnapshot = () => Math.floor(Date.now() / 60000);\nconst fixedSnapshot = () => 0;\nconst serverSnapshot = () => -1;\n\nexport function OpenNowBadge({\n  hours = defaultHours,\n  closedDates,\n  timeZone,\n  now,\n  soonMinutes = 30,\n  hourCycle = 12,\n  size = \"md\",\n  variant = \"soft\",\n  appearance = \"dark\",\n  compact = false,\n  accent = \"#7fb3ff\",\n  labels: labelsProp,\n  onStatusChange,\n  className = \"\",\n  style,\n  ...rest\n}: OpenNowBadgeProps) {\n  const labels = { ...defaultLabels, ...labelsProp };\n  const fixed = now !== undefined;\n  const tick = React.useSyncExternalStore(fixed ? noopSubscribe : subscribeClock, fixed ? fixedSnapshot : clockSnapshot, serverSnapshot);\n  const nowKey = now instanceof Date ? now.getTime() : now;\n\n  const result = React.useMemo<OpenNowResult>(() => {\n    if (tick < 0) return { status: \"unknown\" };\n    const at = nowKey !== undefined ? new Date(nowKey) : new Date(tick * 60000);\n    return getOpenStatus(hours, at, { timeZone, closedDates, soonMinutes });\n  }, [tick, nowKey, timeZone, closedDates, hours, soonMinutes]);\n\n  const latest = React.useRef(onStatusChange);\n  React.useEffect(() => {\n    latest.current = onStatusChange;\n  }, [onStatusChange]);\n\n  const reported = React.useRef<OpenNowStatus>(\"unknown\");\n  React.useEffect(() => {\n    if (result.status === \"unknown\" || result.status === reported.current) return;\n    reported.current = result.status;\n    latest.current?.(result.status, result);\n  }, [result]);\n\n  const time = (clock?: string) => {\n    if (!clock) return \"\";\n    const [h, m] = clock.split(\":\").map(Number);\n    if (hourCycle === 24) return clock;\n    const h12 = h % 12 || 12;\n    return `${m ? `${h12}:${String(m).padStart(2, \"0\")}` : h12} ${h < 12 ? labels.am : labels.pm}`;\n  };\n  const fill = (template: string, values: Record<string, string>) => template.replace(/\\{(\\w+)\\}/g, (_, k: string) => values[k] ?? \"\");\n  const opensLine = () => {\n    if (result.opensAt === undefined || result.opensDay === undefined) return \"\";\n    const day = result.opensInDays === 1 ? labels.tomorrow : labels.days[result.opensDay] ?? \"\";\n    return fill(labels.opens, { day, time: time(result.opensAt) }).replace(/\\s+/g, \" \").trim();\n  };\n\n  let main = labels.checking;\n  let detail = \"\";\n  switch (result.status) {\n    case \"open\":\n      main = compact ? labels.openShort : labels.open;\n      detail = compact ? \"\" : fill(labels.until, { time: time(result.closesAt) });\n      break;\n    case \"closing-soon\":\n      main = labels.closingSoon;\n      detail = compact ? \"\" : fill(labels.until, { time: time(result.closesAt) });\n      break;\n    case \"opening-later\":\n      main = fill(compact ? labels.opensShort : labels.openingAt, { time: time(result.opensAt) });\n      break;\n    case \"closed\":\n      main = labels.closed;\n      detail = compact ? \"\" : opensLine();\n      break;\n    case \"closed-today\":\n      main = labels.closedToday;\n      detail = compact ? \"\" : opensLine();\n      break;\n  }\n\n  const vars = { \"--hb-oa3-accent\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <span\n      role=\"status\"\n      aria-live=\"polite\"\n      className={`hb-oa3 ${className}`}\n      style={vars}\n      data-status={result.status}\n      data-size={size}\n      data-variant={variant}\n      data-appearance={appearance}\n      {...rest}\n    >\n      <style href=\"hb-open-now-badge\" precedence=\"default\">{css}</style>\n      <span className=\"hb-oa3-dot\" aria-hidden=\"true\" />\n      <span className=\"hb-oa3-main\">{main}</span>\n      {detail ? (\n        <>\n          <span className=\"hb-oa3-sep\" aria-hidden=\"true\">·</span>\n          <span className=\"hb-oa3-detail\">{detail}</span>\n        </>\n      ) : null}\n    </span>\n  );\n}\n"
    }
  ]
}