{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "schedule-04",
  "description": "The next seven days on a shared time axis, with how many events each day holds and how much of it is booked.",
  "registryDependencies": [
    "card",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/chart.json",
    "https://www.dashboardblocks.com/r/radix/schedule.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/schedule/schedule-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  ChartFloatingTooltip,\n  ChartPlaceholder,\n  ChartTooltipItem,\n} from '@/registry/components/dashboardblocks/chart'\nimport {\n  EventSwatch,\n  type ScheduleEvent,\n  addDays,\n  formatDuration,\n  formatTimeRange,\n  getDay,\n  getEventStyle,\n} from '@/registry/components/dashboardblocks/schedule'\nimport { dayIn, formatDate, zonedParts } from '@/registry/lib/dashboardblocks/format'\nimport { useRef, useState } from 'react'\n\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface Schedule4Props extends BlockStateProps {\n  calendars: { color: string; name: string }[]\n  /** Last hour on the axis, 1–24. */\n  endHour?: number\n  /** Leave out, or pass none, to show the empty state. */\n  events?: ScheduleEvent[]\n  now: Date\n  /** First hour on the axis, 0–23. */\n  startHour?: number\n  /** @default 'UTC' */\n  timeZone?: string\n  title: string\n}\n\nconst NOW = Date.UTC(2026, 8, 28, 9, 40)\nconst at = (day: number, hour: number, minute = 0) =>\n  new Date(Date.UTC(2026, 8, 28 + day, hour, minute))\n\nconst CALENDARS = {\n  customers: { calendar: 'Customers', color: 'var(--color-chart-3)' },\n  focus: { calendar: 'Focus', color: 'var(--color-chart-5)' },\n  product: { calendar: 'Product', color: 'var(--color-chart-2)' },\n  team: { calendar: 'Team', color: 'var(--color-chart-4)' },\n}\n\nconst exampleProps: Schedule4Props = {\n  calendars: Object.values(CALENDARS).map(({ calendar, color }) => ({\n    color,\n    name: calendar,\n  })),\n  events: [\n    {\n      ...CALENDARS.team,\n      end: at(0, 9, 15),\n      id: 'w1',\n      start: at(0, 9),\n      title: 'Standup',\n    },\n    {\n      ...CALENDARS.product,\n      end: at(0, 10, 30),\n      id: 'w2',\n      start: at(0, 9, 30),\n      title: 'Roadmap review',\n    },\n    {\n      ...CALENDARS.customers,\n      end: at(0, 14, 45),\n      id: 'w3',\n      start: at(0, 14),\n      title: 'Northwind onboarding',\n    },\n    {\n      ...CALENDARS.focus,\n      end: at(0, 17),\n      id: 'w4',\n      start: at(0, 15),\n      title: 'Focus time',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(1, 9, 15),\n      id: 'w5',\n      start: at(1, 9),\n      title: 'Standup',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(1, 13),\n      id: 'w6',\n      start: at(1, 12),\n      title: 'Team lunch',\n    },\n    {\n      ...CALENDARS.customers,\n      end: at(1, 16, 30),\n      id: 'w7',\n      start: at(1, 15, 30),\n      title: 'Acme QBR',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(2, 9, 15),\n      id: 'w8',\n      start: at(2, 9),\n      title: 'Standup',\n    },\n    {\n      ...CALENDARS.product,\n      end: at(2, 11),\n      id: 'w9',\n      start: at(2, 10),\n      title: 'Design critique',\n    },\n    {\n      ...CALENDARS.customers,\n      end: at(2, 11, 30),\n      id: 'w10',\n      start: at(2, 10, 30),\n      title: 'Initech demo',\n    },\n    {\n      ...CALENDARS.product,\n      end: at(2, 16),\n      id: 'w11',\n      start: at(2, 13),\n      title: 'v4.2 release window',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(3, 9, 15),\n      id: 'w12',\n      start: at(3, 9),\n      title: 'Standup',\n    },\n    {\n      ...CALENDARS.focus,\n      end: at(3, 12),\n      id: 'w13',\n      start: at(3, 9, 30),\n      title: 'Focus time',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(4, 9, 15),\n      id: 'w14',\n      start: at(4, 9),\n      title: 'Standup',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(4, 17),\n      id: 'w15',\n      start: at(4, 16),\n      title: 'Sprint retro',\n    },\n  ],\n  now: new Date(NOW),\n  title: 'Week ahead',\n}\n\nfunction assignLanes(events: ScheduleEvent[]) {\n  const laneEnds: number[] = []\n  return events.map((event) => {\n    const start = event.start.getTime()\n    const end = (event.end ?? event.start).getTime()\n    let lane = laneEnds.findIndex((laneEnd) => laneEnd <= start)\n    if (lane === -1) lane = laneEnds.length\n    laneEnds[lane] = end\n    return { event, lane }\n  })\n}\n\nfunction getBookedMinutes(events: ScheduleEvent[]) {\n  let total = 0\n  let until = -Infinity\n  for (const event of events) {\n    const start = Math.max(event.start.getTime(), until)\n    const end = (event.end ?? event.start).getTime()\n    if (end > start) total += (end - start) / 60_000\n    until = Math.max(until, end)\n  }\n  return total\n}\n\nconst formatHour = (hour: number) =>\n  `${hour % 12 || 12}${hour < 12 || hour === 24 ? 'a' : 'p'}`\n\ninterface HoveredEvent {\n  event: ScheduleEvent\n  flip: boolean\n  x: number\n  y: number\n}\n\nconst Schedule4 = (props: Schedule4Props) => {\n  const {\n    calendars,\n    endHour = 18,\n    events = [],\n    now,\n    startHour = 8,\n    errorMessage,\n    status,\n    timeZone = 'UTC',\n    title,\n  } = props\n  const frame = useRef<HTMLDivElement>(null)\n  const [hovered, setHovered] = useState<HoveredEvent | null>(null)\n  const state = getBlockState(status, events)\n  const today = getDay(now, timeZone)\n  const range = (endHour - startHour) * 60\n  const ticks = Array.from(\n    { length: Math.floor((endHour - startHour) / 2) + 1 },\n    (_, index) => startHour + index * 2,\n  )\n  const position = (date: Date) => {\n    const { hour, minute } = zonedParts(date, timeZone)\n    const minutes = hour * 60 + minute - startHour * 60\n    return Math.min(1, Math.max(0, minutes / range)) * 100\n  }\n\n  const days = Array.from({ length: 7 }, (_, index) => {\n    const day = addDays(today, index)\n    const key = day.toISOString().slice(0, 10)\n    const dayEvents = events\n      .filter((event) => dayIn(event.start, timeZone) === key)\n      .sort((a, b) => a.start.getTime() - b.start.getTime())\n    const timed = dayEvents.filter((event) => !event.allDay)\n    return {\n      allDay: dayEvents.filter((event) => event.allDay),\n      booked: getBookedMinutes(timed),\n      day,\n      key,\n      lanes: assignLanes(timed),\n    }\n  })\n  const totalEvents = days.reduce(\n    (sum, day) => sum + day.lanes.length + day.allDay.length,\n    0,\n  )\n  const totalBooked = days.reduce((sum, day) => sum + day.booked, 0)\n  const busiest = days.reduce((top, day) => (day.booked > top.booked ? day : top))\n  const nowPosition = position(now)\n  const booked = (minutes: number) =>\n    minutes === 0 ? 'Free' : formatDuration(new Date(0), new Date(minutes * 60_000))\n  const dayName = (day: Date, index: number) =>\n    index === 0 ? 'today' : formatDate(day, 'weekday-long')\n\n  const show = (event: ScheduleEvent, bar: HTMLElement) => {\n    const origin = frame.current?.getBoundingClientRect()\n    if (!origin) return\n    const box = bar.getBoundingClientRect()\n    const x = box.left - origin.left + box.width / 2\n    setHovered({\n      event,\n      flip: x > origin.width / 2,\n      x,\n      y: box.top - origin.top + box.height / 2,\n    })\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex flex-col gap-0.5'>\n              <h2 className='font-semibold tracking-tight'>{title}</h2>\n              <BlockReady className='text-sm'>\n                <p className='text-muted-foreground text-sm'>\n                  {totalEvents} {totalEvents === 1 ? 'event' : 'events'} in the next 7\n                  days, {totalBooked === 0 ? 'nothing' : booked(totalBooked)} booked.\n                  {busiest.booked > 0 && (\n                    <>\n                      {' '}\n                      The busiest day is {dayName(busiest.day, days.indexOf(busiest))},\n                      with {booked(busiest.booked)} of meetings.\n                    </>\n                  )}\n                </p>\n              </BlockReady>\n            </header>\n            <div ref={frame} className='relative flex flex-col gap-2 border-t pt-3'>\n              <div\n                aria-hidden\n                className='text-muted-foreground grid grid-cols-1 text-xs tabular-nums @lg:grid-cols-[5rem_minmax(0,1fr)_11rem] @lg:gap-x-3'\n              >\n                <div className='relative h-4 @lg:col-start-2'>\n                  {ticks.map((hour) => (\n                    <span\n                      key={hour}\n                      className={cn(\n                        'absolute -translate-x-1/2',\n                        hour === startHour && 'translate-x-0',\n                        hour === endHour && '-translate-x-full',\n                      )}\n                      style={{\n                        left: `${(((hour - startHour) * 60) / range) * 100}%`,\n                      }}\n                    >\n                      {formatHour(hour)}\n                    </span>\n                  ))}\n                </div>\n              </div>\n              {state === 'loading' && (\n                <>\n                  <span className='sr-only'>Loading</span>\n                  <ChartPlaceholder height={272} />\n                </>\n              )}\n              {state && state !== 'loading' && (\n                <BlockStateText className='py-2.5 text-sm' />\n              )}\n              {!state && (\n                <ol className='flex flex-col gap-3 @lg:gap-2'>\n                  {days.map(({ allDay, booked: minutes, day, key, lanes }, index) => {\n                    const laneCount = Math.max(1, ...lanes.map(({ lane }) => lane + 1))\n                    const count = lanes.length + allDay.length\n                    return (\n                      <li\n                        key={key}\n                        className='grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-1.5 @lg:grid-cols-[5rem_minmax(0,1fr)_11rem]'\n                      >\n                        <h3 className='min-w-0 text-sm'>\n                          <span aria-hidden className='font-medium'>\n                            {index === 0\n                              ? 'Today'\n                              : `${formatDate(day, 'weekday')} ${day.getUTCDate()}`}\n                          </span>\n                          <span className='sr-only'>\n                            {index === 0 && 'Today, '}\n                            {formatDate(day, 'weekday-long-day')}\n                          </span>\n                          {allDay.map((event) => (\n                            <span\n                              key={event.id}\n                              className='text-muted-foreground block truncate text-xs'\n                            >\n                              {event.title} (all day)\n                            </span>\n                          ))}\n                        </h3>\n                        <p className='text-muted-foreground flex justify-end gap-3 text-sm whitespace-nowrap tabular-nums @lg:order-last'>\n                          {count === 0\n                            ? 'No events'\n                            : `${count} ${count === 1 ? 'event' : 'events'}`}\n                          {count > 0 && (\n                            <span className='hidden w-20 text-right @lg:inline'>\n                              <span className='sr-only'>, </span>\n                              {booked(minutes)}\n                            </span>\n                          )}\n                        </p>\n                        <div\n                          className='bg-muted/30 relative col-span-2 rounded-md @lg:col-span-1'\n                          style={{\n                            height: `calc(${laneCount} * 1.5rem + 0.5rem)`,\n                          }}\n                        >\n                          {ticks.slice(1, -1).map((hour) => (\n                            <span\n                              key={hour}\n                              aria-hidden\n                              className='bg-border absolute inset-y-0 w-px'\n                              style={{\n                                left: `${(((hour - startHour) * 60) / range) * 100}%`,\n                              }}\n                            />\n                          ))}\n                          <ul>\n                            {lanes.map(({ event, lane }) => {\n                              const left = Math.min(98, position(event.start))\n                              const width = Math.max(\n                                2,\n                                position(event.end ?? event.start) - left,\n                              )\n                              const ended = (event.end ?? event.start) <= now\n                              const minutes =\n                                ((event.end ?? event.start).getTime() -\n                                  event.start.getTime()) /\n                                60_000\n                              return (\n                                <li\n                                  key={event.id}\n                                  onPointerEnter={(pointer) =>\n                                    show(event, pointer.currentTarget)\n                                  }\n                                  onPointerDown={(pointer) =>\n                                    show(event, pointer.currentTarget)\n                                  }\n                                  onPointerLeave={() => setHovered(null)}\n                                  className={cn(\n                                    'absolute flex h-5 items-center overflow-hidden rounded-sm px-1 text-xs leading-none font-medium',\n                                    ended && 'text-muted-foreground',\n                                  )}\n                                  style={{\n                                    ...getEventStyle(\n                                      event,\n                                      ended,\n                                      'var(--color-background)',\n                                    ),\n                                    left: `${left}%`,\n                                    top: `calc(${lane} * 1.5rem + 0.25rem)`,\n                                    width: `${width}%`,\n                                  }}\n                                >\n                                  <span className='sr-only'>\n                                    {formatTimeRange(event.start, event.end, timeZone)}\n                                    {event.calendar && `, ${event.calendar}`}\n                                    {ended && ', ended'}:{' '}\n                                  </span>\n                                  <span\n                                    className={cn(\n                                      'truncate',\n                                      minutes < 60 && 'sr-only',\n                                      minutes < 120 && '@max-md:sr-only',\n                                    )}\n                                  >\n                                    {event.title}\n                                  </span>\n                                </li>\n                              )\n                            })}\n                          </ul>\n                          {index === 0 && nowPosition > 0 && nowPosition < 100 && (\n                            <span\n                              aria-hidden\n                              className='bg-foreground ring-background absolute -inset-y-1 w-0.5 -translate-x-1/2 rounded-full ring-2'\n                              style={{ left: `${nowPosition}%` }}\n                            />\n                          )}\n                        </div>\n                      </li>\n                    )\n                  })}\n                </ol>\n              )}\n              {!state && hovered && (\n                <ChartFloatingTooltip\n                  active\n                  flip={hovered.flip}\n                  x={hovered.x}\n                  y={hovered.y}\n                >\n                  <span className='font-medium'>{hovered.event.title}</span>\n                  <ChartTooltipItem\n                    color={hovered.event.color ?? 'var(--color-chart-2)'}\n                    name={hovered.event.calendar}\n                    value={formatTimeRange(\n                      hovered.event.start,\n                      hovered.event.end,\n                      timeZone,\n                    )}\n                  />\n                </ChartFloatingTooltip>\n              )}\n            </div>\n            {!state && (\n              <ul className='text-muted-foreground flex flex-wrap gap-x-4 gap-y-1 text-xs'>\n                {calendars.map((calendar) => (\n                  <li key={calendar.name} className='flex items-center gap-1.5'>\n                    <EventSwatch color={calendar.color} />\n                    {calendar.name}\n                  </li>\n                ))}\n                <li aria-hidden className='flex items-center gap-1.5'>\n                  <span className='bg-foreground h-3 w-0.5 rounded-full' />\n                  Now\n                </li>\n              </ul>\n            )}\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport { Schedule4, exampleProps as schedule4ExampleProps, type Schedule4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/schedule/schedule-04.tsx"
    }
  ],
  "meta": {
    "shows": "The next seven days on a shared time axis, with how many events each day holds and how much of it is booked.",
    "size": "full",
    "usedWith": [
      "schedule-01",
      "team-02"
    ],
    "component": "Schedule4",
    "props": "{ calendars: { color: string; name: string }[]; endHour?: number; events?: { allDay?: boolean; calendar?: string; color?: string; end?: Date; id: string; location?: string; start: Date; title: string }[]; now: Date; startHour?: number; timeZone?: string; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
