{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"opening-hours","type":"registry:ui","title":"Opening hours","description":"Weekly hours list with today highlighted, live open status, split shifts and closed days.","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"registry/items/opening-hours/opening-hours.tsx","type":"registry:ui","target":"components/facade/opening-hours.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { motion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\n/* ------------------------------------------------------------------\n   Hours model (same shape as open-now-badge, duplicated so this\n   item installs on its own)\n------------------------------------------------------------------- */\n\nexport type DayKey = \"sun\" | \"mon\" | \"tue\" | \"wed\" | \"thu\" | \"fri\" | \"sat\";\n\n/** 24h \"HH:mm\". A close time earlier than (or equal to) open runs past midnight. */\nexport interface TimeRange {\n  open: string;\n  close: string;\n}\n\n/** Missing day, `null` or an empty array means closed. Multiple ranges = split hours. */\nexport type WeeklyHours = Partial<Record<DayKey, TimeRange[] | null>>;\n\nconst DAY_KEYS: DayKey[] = [\"sun\", \"mon\", \"tue\", \"wed\", \"thu\", \"fri\", \"sat\"];\nconst SHORT_DAYS = [\"Sun\", \"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\"];\nconst DAY_NAMES = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"];\n\nfunction toMinutes(t: string): number {\n  const [h, m = \"0\"] = t.split(\":\");\n  return Number(h) * 60 + Number(m);\n}\n\nfunction formatClock(total: number): string {\n  const mins = ((total % 1440) + 1440) % 1440;\n  const h = Math.floor(mins / 60);\n  const m = mins % 60;\n  if (h === 0 && m === 0) return \"12 AM\";\n  const period = h < 12 ? \"AM\" : \"PM\";\n  const h12 = h % 12 || 12;\n  return m ? `${h12}:${String(m).padStart(2, \"0\")} ${period}` : `${h12} ${period}`;\n}\n\nfunction zonedNow(date: Date, timeZone: string): { day: number; minutes: number } {\n  const parts = new Intl.DateTimeFormat(\"en-US\", {\n    timeZone,\n    weekday: \"short\",\n    hour: \"numeric\",\n    minute: \"numeric\",\n    hourCycle: \"h23\",\n  }).formatToParts(date);\n  const get = (type: Intl.DateTimeFormatPartTypes) => parts.find((p) => p.type === type)?.value ?? \"0\";\n  return {\n    day: Math.max(0, SHORT_DAYS.indexOf(get(\"weekday\"))),\n    minutes: (Number(get(\"hour\")) % 24) * 60 + Number(get(\"minute\")),\n  };\n}\n\nfunction isOpenAt(hours: WeeklyHours, day: number, minutes: number): boolean {\n  const today = hours[DAY_KEYS[day]] ?? [];\n  for (const r of today) {\n    const s = toMinutes(r.open);\n    let e = toMinutes(r.close);\n    if (e <= s) e += 1440;\n    if (minutes >= s && minutes < e) return true;\n  }\n  // Overnight spill from yesterday.\n  const yesterday = hours[DAY_KEYS[(day + 6) % 7]] ?? [];\n  for (const r of yesterday) {\n    const s = toMinutes(r.open);\n    const e = toMinutes(r.close);\n    if (e <= s && minutes < e) return true;\n  }\n  return false;\n}\n\n/* ------------------------------------------------------------------\n   Component\n------------------------------------------------------------------- */\n\nexport interface OpeningHoursProps {\n  /** Weekly schedule. Defaults to a Monday to Saturday storefront example. */\n  hours?: WeeklyHours;\n  /** IANA time zone of the business, e.g. \"America/Los_Angeles\". Defaults to \"America/New_York\". */\n  timeZone?: string;\n  /** First row of the list. US convention is Monday or Sunday. */\n  weekStartsOn?: \"mon\" | \"sun\";\n  title?: string;\n  /** Optional footnote, e.g. holiday hours. */\n  note?: string;\n  className?: string;\n}\n\nconst WEEKDAY_HOURS: TimeRange[] = [{ open: \"09:00\", close: \"18:00\" }];\nconst DEFAULT_HOURS: WeeklyHours = {\n  mon: WEEKDAY_HOURS,\n  tue: WEEKDAY_HOURS,\n  wed: WEEKDAY_HOURS,\n  thu: WEEKDAY_HOURS,\n  fri: WEEKDAY_HOURS,\n  sat: [{ open: \"10:00\", close: \"16:00\" }],\n  sun: null,\n};\n\nexport function OpeningHours({\n  hours = DEFAULT_HOURS,\n  timeZone = \"America/New_York\",\n  weekStartsOn = \"mon\",\n  title = \"Hours\",\n  note,\n  className,\n}: OpeningHoursProps) {\n  const uid = React.useId();\n  const [now, setNow] = React.useState<{ day: number; minutes: number } | null>(null);\n\n  React.useEffect(() => {\n    const tick = () => setNow(zonedNow(new Date(), timeZone));\n    tick();\n    const id = window.setInterval(tick, 30_000);\n    return () => window.clearInterval(id);\n  }, [timeZone]);\n\n  const order = weekStartsOn === \"mon\" ? [1, 2, 3, 4, 5, 6, 0] : [0, 1, 2, 3, 4, 5, 6];\n  const open = now ? isOpenAt(hours, now.day, now.minutes) : null;\n  const tzLabel = React.useMemo(() => {\n    try {\n      const part = new Intl.DateTimeFormat(\"en-US\", { timeZone, timeZoneName: \"short\" })\n        .formatToParts(new Date())\n        .find((p) => p.type === \"timeZoneName\");\n      return part?.value ?? \"\";\n    } catch {\n      return \"\";\n    }\n  }, [timeZone]);\n\n  return (\n    <section aria-label={title} className={cn(\"w-full rounded-[28px] bg-muted p-6 text-foreground\", className)}>\n      <header className=\"mb-4 flex items-start justify-between gap-4\">\n        <div className=\"min-w-0\">\n          <h3 className=\"font-display text-[19px] font-semibold tracking-[-0.02em]\">{title}</h3>\n          {tzLabel && <p className=\"mt-0.5 text-[13px] text-muted-foreground\">Times in {tzLabel}</p>}\n        </div>\n        <span\n          className={cn(\n            \"inline-flex h-7 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full bg-background px-3 text-[13px] font-medium transition-colors\",\n            open === null && \"text-transparent\",\n            open === true && \"text-success\",\n            open === false && \"text-muted-foreground\",\n          )}\n          aria-live=\"polite\"\n        >\n          <span\n            className={cn(\n              \"size-1.5 rounded-full\",\n              open ? \"bg-success\" : \"bg-muted-foreground/50\",\n              open === null && \"bg-transparent\",\n            )}\n            aria-hidden\n          />\n          {open === null ? \"Loading\" : open ? \"Open now\" : \"Closed now\"}\n        </span>\n      </header>\n\n      <ul className=\"relative -mx-3\">\n        {order.map((d) => {\n          const ranges = hours[DAY_KEYS[d]] ?? [];\n          const isToday = now?.day === d;\n          return (\n            <li\n              key={d}\n              aria-current={isToday ? \"date\" : undefined}\n              className=\"relative flex items-start justify-between gap-4 px-3 py-2.5 text-[15px]\"\n            >\n              {isToday && (\n                <motion.span\n                  layoutId={`${uid}-today`}\n                  className=\"absolute inset-0 rounded-xl bg-background\"\n                  transition={{ type: \"spring\", stiffness: 400, damping: 36 }}\n                  initial={{ opacity: 0 }}\n                  animate={{ opacity: 1 }}\n                  aria-hidden\n                />\n              )}\n              <span\n                className={cn(\n                  \"relative flex items-baseline gap-2\",\n                  isToday ? \"font-medium text-foreground\" : \"text-muted-foreground\",\n                )}\n              >\n                <span className=\"sm:hidden\">{SHORT_DAYS[d]}</span>\n                <span className=\"hidden sm:inline\">{DAY_NAMES[d]}</span>\n                {isToday && <span className=\"text-[12px] font-medium text-brand\">Today</span>}\n              </span>\n              <span className=\"relative flex flex-col items-end gap-0.5 text-right\">\n                {ranges.length === 0 ? (\n                  <span className={cn(isToday ? \"text-destructive\" : \"text-muted-foreground/70\")}>Closed</span>\n                ) : (\n                  ranges.map((r) => {\n                    const s = toMinutes(r.open);\n                    const e = toMinutes(r.close);\n                    const allDay = s === e;\n                    return (\n                      <span\n                        key={`${r.open}-${r.close}`}\n                        className={cn(\"tabular-nums\", isToday ? \"font-medium text-foreground\" : \"text-foreground/85\")}\n                      >\n                        {allDay ? \"Open 24 hours\" : `${formatClock(s)} to ${formatClock(e)}`}\n                      </span>\n                    );\n                  })\n                )}\n              </span>\n            </li>\n          );\n        })}\n      </ul>\n\n      {note && <p className=\"mt-5 text-[13px] leading-relaxed text-muted-foreground\">{note}</p>}\n    </section>\n  );\n}\n\nexport default OpeningHours;\n"}],"categories":["local-business"],"meta":{"tier":"free","demo":"\"use client\";\n\nimport { OpeningHours, type WeeklyHours } from \"./opening-hours\";\n\nconst hours: WeeklyHours = {\n  mon: null,\n  tue: [{ open: \"11:30\", close: \"14:30\" }, { open: \"17:00\", close: \"22:00\" }],\n  wed: [{ open: \"11:30\", close: \"14:30\" }, { open: \"17:00\", close: \"22:00\" }],\n  thu: [{ open: \"11:30\", close: \"14:30\" }, { open: \"17:00\", close: \"22:00\" }],\n  fri: [{ open: \"11:30\", close: \"14:30\" }, { open: \"17:00\", close: \"23:30\" }],\n  sat: [{ open: \"10:00\", close: \"23:30\" }],\n  sun: [{ open: \"10:00\", close: \"15:00\" }],\n};\n\nexport default function Demo() {\n  return (\n    <div className=\"mx-auto w-full max-w-[400px]\">\n      <OpeningHours\n        title=\"Alder & Vine\"\n        hours={hours}\n        timeZone=\"America/Los_Angeles\"\n        note=\"Pearl District, Portland. Brunch served Saturday and Sunday until 2 PM. Kitchen closes 30 minutes before close. Closed Thanksgiving Day.\"\n      />\n    </div>\n  );\n}\n"}}