{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-04",
  "description": "A day of meeting room bookings with a column per room and whether each is free right now.",
  "registryDependencies": [
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/calendar.json",
    "https://www.dashboardblocks.com/r/radix/schedule.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/calendar/calendar-04.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateText,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type CalendarEvent,\n  CalendarEventDetails,\n  CalendarLegend,\n  type CalendarResource,\n  CalendarResourceView,\n  CalendarToolbar,\n  getEventsForDay,\n} from '@/registry/components/dashboardblocks/calendar'\nimport {\n  addDays,\n  formatTime,\n  getDay,\n} from '@/registry/components/dashboardblocks/schedule'\nimport { StatusLabel } from '@/registry/components/dashboardblocks/status-label'\nimport { formatDate } from '@/registry/lib/dashboardblocks/format'\nimport { useRef, useState } from 'react'\n\ninterface Room {\n  id: string\n  name: string\n  seats: number\n}\n\ninterface Calendar4Props extends BlockStateProps {\n  /** Leave out, or pass none, to show the empty state. */\n  bookings?: CalendarEvent[]\n  endHour?: number\n  now: Date\n  onSelectBooking?: (booking: CalendarEvent) => void\n  rooms: Room[]\n  startHour?: number\n  teams: { color: string; name: string }[]\n  /** @default 'UTC' */\n  timeZone?: 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, day, hour, minute))\n\nconst TEAMS = {\n  design: { calendar: 'Design', color: 'var(--color-chart-4)' },\n  engineering: { calendar: 'Engineering', color: 'var(--color-chart-2)' },\n  leadership: { calendar: 'Leadership', color: 'var(--color-chart-1)' },\n  people: { calendar: 'People', color: 'var(--color-chart-5)' },\n  sales: { calendar: 'Sales', color: 'var(--color-chart-3)' },\n}\n\nconst exampleProps: Calendar4Props = {\n  bookings: [\n    {\n      ...TEAMS.engineering,\n      attendees: [\n        { name: 'Maya Lindqvist' },\n        { name: 'Tomás Herrera' },\n        { name: 'Jonah Adeyemi' },\n      ],\n      description: 'Sprint 42 planning. Estimates are in the board, bring questions.',\n      end: at(28, 10, 30),\n      id: 'b1',\n      resource: 'atlas',\n      start: at(28, 9),\n      title: 'Sprint planning',\n    },\n    {\n      ...TEAMS.people,\n      attendees: [{ name: 'Grace Liu' }, { name: 'Jonas Weber' }],\n      end: at(28, 11, 30),\n      id: 'b2',\n      resource: 'lisbon',\n      start: at(28, 10, 30),\n      title: 'Interview: Jonas Weber',\n    },\n    {\n      ...TEAMS.sales,\n      attendees: [{ name: 'Priya Raman' }, { name: 'Marcus Reid' }],\n      description: 'On-site demo for Acme’s finance team. Guests sign in at reception.',\n      end: at(28, 12),\n      id: 'b3',\n      resource: 'boardroom',\n      start: at(28, 11),\n      title: 'Acme demo',\n    },\n    {\n      ...TEAMS.design,\n      attendees: [{ name: 'Ana Sousa' }, { name: 'Leo Park' }],\n      end: at(28, 12),\n      id: 'b4',\n      resource: 'studio',\n      start: at(28, 8, 30),\n      title: 'Usability sessions',\n    },\n    {\n      ...TEAMS.leadership,\n      attendees: [{ name: 'Elena Novak' }, { name: 'David Kim' }],\n      end: at(28, 9, 30),\n      id: 'b5',\n      resource: 'boardroom',\n      start: at(28, 8),\n      title: 'Exec breakfast',\n    },\n    {\n      ...TEAMS.engineering,\n      end: at(28, 13),\n      id: 'b6',\n      resource: 'pod',\n      start: at(28, 10),\n      title: 'Incident review write-up',\n    },\n    {\n      ...TEAMS.sales,\n      end: at(28, 14, 45),\n      id: 'b7',\n      resource: 'lisbon',\n      start: at(28, 14),\n      title: 'Northwind onboarding',\n    },\n    {\n      ...TEAMS.leadership,\n      attendees: [\n        { name: 'Elena Novak' },\n        { name: 'David Kim' },\n        { name: 'Priya Raman' },\n      ],\n      description: 'Prep for the October board meeting: Q3 numbers and the 2027 plan.',\n      end: at(28, 16),\n      id: 'b8',\n      resource: 'boardroom',\n      start: at(28, 14),\n      title: 'Board prep',\n    },\n    {\n      ...TEAMS.design,\n      end: at(28, 15),\n      id: 'b9',\n      resource: 'atlas',\n      start: at(28, 13, 30),\n      title: 'Design review',\n    },\n    {\n      ...TEAMS.people,\n      end: at(28, 17),\n      id: 'b10',\n      resource: 'atlas',\n      start: at(28, 16),\n      title: 'Hiring panel debrief',\n    },\n    {\n      ...TEAMS.engineering,\n      end: at(28, 17, 30),\n      id: 'b11',\n      resource: 'studio',\n      start: at(28, 16, 30),\n      title: 'Podcast: SaaS Weekly',\n    },\n    {\n      ...TEAMS.people,\n      allDay: true,\n      id: 'b12',\n      resource: 'pod',\n      start: at(29, 0),\n      title: 'Closed for cleaning',\n    },\n    {\n      ...TEAMS.engineering,\n      end: at(29, 11),\n      id: 'b13',\n      resource: 'atlas',\n      start: at(29, 10),\n      title: 'Architecture review',\n    },\n    {\n      ...TEAMS.sales,\n      end: at(29, 16, 30),\n      id: 'b14',\n      resource: 'boardroom',\n      start: at(29, 15, 30),\n      title: 'Acme QBR',\n    },\n    {\n      ...TEAMS.people,\n      end: at(29, 13),\n      id: 'b15',\n      resource: 'lisbon',\n      start: at(29, 12),\n      title: 'Benefits Q&A',\n    },\n  ],\n  now: new Date(NOW),\n  rooms: [\n    { id: 'atlas', name: 'Atlas', seats: 8 },\n    { id: 'boardroom', name: 'Boardroom', seats: 14 },\n    { id: 'lisbon', name: 'Lisbon', seats: 4 },\n    { id: 'studio', name: 'Studio', seats: 6 },\n    { id: 'pod', name: 'Focus pod', seats: 2 },\n  ],\n  teams: Object.values(TEAMS).map(({ calendar, color }) => ({\n    color,\n    name: calendar,\n  })),\n}\n\nfunction getRoomStatus(bookings: CalendarEvent[], now: Date, timeZone: string) {\n  if (bookings.some((booking) => booking.allDay))\n    return { busy: true, label: 'Closed today', tone: 'neutral' as const }\n  const times = bookings\n    .map((booking) => ({ end: booking.end ?? booking.start, start: booking.start }))\n    .sort((a, b) => a.start.getTime() - b.start.getTime())\n  const current = times.find(({ end, start }) => start <= now && now < end)\n  if (current) {\n    let until = current.end\n    for (const { end, start } of times) {\n      if (start <= until && end > until) until = end\n    }\n    return {\n      busy: true,\n      label: `In use until ${formatTime(until, timeZone)}`,\n      tone: 'warning' as const,\n    }\n  }\n  const next = times.find(({ start }) => start > now)\n  return {\n    busy: false,\n    label: next\n      ? `Free until ${formatTime(next.start, timeZone)}`\n      : 'Free for the rest of today',\n    tone: 'good' as const,\n  }\n}\n\nconst Calendar4 = (props: Calendar4Props) => {\n  const {\n    bookings: data = [],\n    endHour = 19,\n    now,\n    onSelectBooking,\n    rooms,\n    startHour = 7,\n    errorMessage,\n    status: blockStatus,\n    teams,\n    timeZone = 'UTC',\n  } = props\n  const state = getBlockState(blockStatus, data)\n  const bookings = state ? [] : data\n  const today = getDay(now, timeZone)\n  const [day, setDay] = useState(today)\n  const [selectedId, setSelectedId] = useState<string>()\n  const container = useRef<HTMLDivElement>(null)\n\n  const isToday = day.getTime() === today.getTime()\n  const dayBookings = getEventsForDay(bookings, day, timeZone)\n  const selected = dayBookings.find((booking) => booking.id === selectedId)\n  let freeNow = 0\n  const resources: CalendarResource[] = rooms.map((room) => {\n    const status =\n      isToday && !state\n        ? getRoomStatus(\n            dayBookings.filter((booking) => booking.resource === room.id),\n            now,\n            timeZone,\n          )\n        : undefined\n    if (status && !status.busy) freeNow++\n    return {\n      description: (\n        <>\n          <span className='block truncate'>{room.seats} seats</span>\n          {status && (\n            <StatusLabel\n              variant='text'\n              tone={status.tone}\n              className='block truncate text-xs'\n            >\n              {status.label}\n            </StatusLabel>\n          )}\n        </>\n      ),\n      id: room.id,\n      name: room.name,\n    }\n  })\n\n  const showDay = (next: Date) => {\n    setDay(next)\n    setSelectedId(undefined)\n  }\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <section className='@container flex flex-col gap-4 [--calendar-surface:var(--color-background)]'>\n        <CalendarToolbar\n          title={formatDate(day, 'weekday-long-day')}\n          description={\n            state ? (\n              <BlockStateText />\n            ) : (\n              `${dayBookings.length} ${dayBookings.length === 1 ? 'booking' : 'bookings'} across ${rooms.length} rooms.${isToday ? ` ${freeNow} ${freeNow === 1 ? 'room is' : 'rooms are'} free right now.` : ''}`\n            )\n          }\n          onToday={() => showDay(today)}\n          onPrevious={() => showDay(addDays(day, -1))}\n          onNext={() => showDay(addDays(day, 1))}\n          previousLabel='Previous day'\n          nextLabel='Next day'\n        />\n        <div ref={container} className='flex flex-col gap-4'>\n          <CalendarResourceView\n            day={day}\n            resources={resources}\n            events={dayBookings}\n            now={now}\n            startHour={startHour}\n            endHour={endHour}\n            onSelectEvent={(booking) => {\n              setSelectedId(booking.id)\n              onSelectBooking?.(booking)\n            }}\n            selectedEventId={selectedId}\n            timeZone={timeZone}\n            minColumnWidth='9.5rem'\n            className='h-[28rem]'\n          />\n          {selected ? (\n            <CalendarEventDetails\n              event={{\n                ...selected,\n                location: rooms.find((room) => room.id === selected.resource)?.name,\n              }}\n              timeZone={timeZone}\n              onClose={() => {\n                container.current\n                  ?.querySelector<HTMLElement>(`[data-event-id=\"${selected.id}\"]`)\n                  ?.focus()\n                setSelectedId(undefined)\n              }}\n              className='border-t pt-4'\n            />\n          ) : (\n            !state && (\n              <p className='text-muted-foreground text-sm'>\n                Select a booking to see who booked it.\n              </p>\n            )\n          )}\n        </div>\n        {!state && <CalendarLegend calendars={teams} label='Teams' />}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Calendar4, exampleProps as calendar4ExampleProps, type Calendar4Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/calendar/calendar-04.tsx"
    }
  ],
  "meta": {
    "shows": "A day of meeting room bookings with a column per room and whether each is free right now.",
    "size": "full",
    "usedWith": [
      "calendar-02",
      "schedule-01"
    ],
    "component": "Calendar4",
    "props": "{ bookings?: { attendees?: { avatar?: string; name: string }[]; description?: string; resource?: string; allDay?: boolean; calendar?: string; color?: string; end?: Date; id: string; location?: string; start: Date; title: string }[]; endHour?: number; now: Date; onSelectBooking?: (booking: { attendees?: { avatar?: string; name: string }[]; description?: string; resource?: string; allDay?: boolean; calendar?: string; color?: string; end?: Date; id: string; location?: string; start: Date; title: string }) => void; rooms: { id: string; name: string; seats: number }[]; startHour?: number; teams: { color: string; name: string }[]; timeZone?: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
