{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-02",
  "description": "A week on an hour axis that opens at working hours, with all-day events on top and the selected event's details.",
  "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"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/calendar/calendar-02.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  CalendarToolbar,\n  CalendarWeekView,\n  formatDayRange,\n  getWeekDays,\n} from '@/registry/components/dashboardblocks/calendar'\nimport {\n  addDays,\n  formatDuration,\n  getDay,\n} from '@/registry/components/dashboardblocks/schedule'\nimport { useRef, useState } from 'react'\n\ninterface Calendar2Props extends BlockStateProps {\n  calendars: { color: string; name: string }[]\n  /** Leave out, or pass none, to show the empty state. */\n  events?: CalendarEvent[]\n  now: Date\n  onSelectEvent?: (event: CalendarEvent) => void\n  /** @default 'UTC' */\n  timeZone?: string\n  /** 0 for Sunday, 1 for Monday. */\n  weekStartsOn?: 0 | 1\n}\n\nconst NOW = Date.UTC(2026, 8, 28, 9, 40)\nconst at = (month: number, day: number, hour = 0, minute = 0) =>\n  new Date(Date.UTC(2026, month, 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  away: { calendar: 'Out of office', color: 'var(--color-chart-1)' },\n  product: { calendar: 'Product', color: 'var(--color-chart-2)' },\n  team: { calendar: 'Team', color: 'var(--color-chart-4)' },\n}\n\nconst TEAM = [\n  { name: 'Maya Lindqvist' },\n  { name: 'Tomás Herrera' },\n  { name: 'Priya Raman' },\n  { name: 'Jonah Adeyemi' },\n]\n\nconst standups: CalendarEvent[] = Array.from({ length: 63 }, (_, index) =>\n  addDays(new Date(Date.UTC(2026, 7, 30)), index),\n)\n  .filter((day) => day.getUTCDay() > 0 && day.getUTCDay() < 6)\n  .map((day) => ({\n    ...CALENDARS.team,\n    attendees: TEAM,\n    end: new Date(day.getTime() + (9 * 60 + 15) * 60_000),\n    id: `standup-${day.toISOString().slice(0, 10)}`,\n    location: 'Zoom',\n    start: new Date(day.getTime() + 9 * 3_600_000),\n    title: 'Standup',\n  }))\n\nconst exampleProps: Calendar2Props = {\n  calendars: Object.values(CALENDARS).map(({ calendar, color }) => ({\n    color,\n    name: calendar,\n  })),\n  events: [\n    ...standups,\n    {\n      ...CALENDARS.away,\n      end: at(8, 27, 21, 30),\n      id: 'flight',\n      location: 'SFO → JFK, UA 1542',\n      start: at(8, 27, 16, 5),\n      title: 'Flight to New York',\n    },\n    {\n      ...CALENDARS.product,\n      allDay: true,\n      description: 'Only fixes for release blockers merge until the release ships.',\n      end: at(8, 30),\n      id: 'freeze',\n      start: at(8, 28),\n      title: 'v4.2 code freeze',\n    },\n    {\n      ...CALENDARS.product,\n      attendees: [\n        { name: 'Maya Lindqvist' },\n        { name: 'Tomás Herrera' },\n        { name: 'Ana Sousa' },\n      ],\n      description:\n        'Walk through the Q4 roadmap and agree what moves to Q1. Bring your top three risks.',\n      end: at(8, 28, 10, 30),\n      id: 'roadmap',\n      location: 'Room 4B',\n      start: at(8, 28, 9, 30),\n      title: 'Roadmap review',\n    },\n    {\n      ...CALENDARS.product,\n      attendees: [{ name: 'Ana Sousa' }, { name: 'Leo Park' }],\n      end: at(8, 28, 12),\n      id: 'critique',\n      location: 'Figma',\n      start: at(8, 28, 11),\n      title: 'Design critique',\n    },\n    {\n      ...CALENDARS.team,\n      attendees: [{ name: 'Maya Lindqvist' }, { name: 'Jonah Adeyemi' }],\n      end: at(8, 28, 11),\n      id: 'one-on-one',\n      start: at(8, 28, 10, 30),\n      title: '1:1 Maya / Jonah',\n    },\n    {\n      ...CALENDARS.customers,\n      attendees: [{ name: 'Priya Raman' }, { name: 'Dana Whitfield' }],\n      description: 'Connect their warehouse and set up the first three dashboards.',\n      end: at(8, 28, 14, 45),\n      id: 'northwind',\n      location: 'Google Meet',\n      start: at(8, 28, 14),\n      title: 'Northwind onboarding',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(8, 28, 17),\n      id: 'hiring',\n      location: 'Room 2A',\n      start: at(8, 28, 16),\n      title: 'Hiring panel: Staff engineer',\n    },\n    {\n      ...CALENDARS.team,\n      attendees: TEAM,\n      end: at(8, 29, 10, 45),\n      id: 'sync',\n      location: 'Zoom',\n      start: at(8, 29, 10),\n      title: 'Team sync',\n    },\n    {\n      ...CALENDARS.focus,\n      end: at(8, 29, 15),\n      id: 'focus-1',\n      start: at(8, 29, 13),\n      title: 'Focus time',\n    },\n    {\n      ...CALENDARS.customers,\n      attendees: [\n        { name: 'Priya Raman' },\n        { name: 'Marcus Reid' },\n        { name: 'Ellen Park' },\n      ],\n      description:\n        'Quarterly business review: usage, open tickets and the renewal in January.',\n      end: at(8, 29, 16, 30),\n      id: 'acme',\n      location: 'Zoom',\n      start: at(8, 29, 15, 30),\n      title: 'Acme QBR',\n    },\n    {\n      ...CALENDARS.product,\n      allDay: true,\n      id: 'v42',\n      start: at(8, 30),\n      title: 'v4.2 release',\n    },\n    {\n      ...CALENDARS.away,\n      allDay: true,\n      end: at(9, 3),\n      id: 'priya-ooo',\n      start: at(8, 30),\n      title: 'Priya out of office',\n    },\n    {\n      ...CALENDARS.product,\n      end: at(8, 30, 9),\n      id: 'go-no-go',\n      location: 'Zoom',\n      start: at(8, 30, 8, 30),\n      title: 'Release go/no-go',\n    },\n    {\n      ...CALENDARS.product,\n      end: at(8, 30, 11, 30),\n      id: 'launch-sync',\n      start: at(8, 30, 11),\n      title: 'Launch sync',\n    },\n    {\n      ...CALENDARS.customers,\n      description: 'Live walkthrough of v4.2 for customers, with Q&A.',\n      end: at(8, 30, 18),\n      id: 'webinar',\n      location: 'Zoom Webinar',\n      start: at(8, 30, 17),\n      title: \"Webinar: What's new in 4.2\",\n    },\n    {\n      ...CALENDARS.product,\n      end: at(9, 1, 12),\n      id: 'pricing',\n      location: 'Boardroom',\n      start: at(9, 1, 10),\n      title: 'Pricing workshop',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(9, 1, 13),\n      id: 'lunch-learn',\n      location: 'Kitchen',\n      start: at(9, 1, 12),\n      title: 'Lunch & learn: Postgres at scale',\n    },\n    {\n      ...CALENDARS.customers,\n      end: at(9, 1, 15, 30),\n      id: 'initech',\n      location: 'Zoom',\n      start: at(9, 1, 15),\n      title: 'Initech demo',\n    },\n    {\n      ...CALENDARS.focus,\n      end: at(9, 2, 12),\n      id: 'focus-2',\n      start: at(9, 2, 9, 30),\n      title: 'Focus time',\n    },\n    {\n      ...CALENDARS.team,\n      attendees: TEAM,\n      end: at(9, 2, 17),\n      id: 'retro',\n      location: 'Room 4B',\n      start: at(9, 2, 16),\n      title: 'Sprint retro',\n    },\n    {\n      ...CALENDARS.team,\n      end: at(9, 6, 11),\n      id: 'planning',\n      location: 'Room 4B',\n      start: at(9, 6, 10),\n      title: 'Sprint planning',\n    },\n    {\n      ...CALENDARS.customers,\n      end: at(9, 7, 15),\n      id: 'globex',\n      location: 'Zoom',\n      start: at(9, 7, 14),\n      title: 'Globex renewal',\n    },\n  ],\n  now: new Date(NOW),\n}\n\nconst Calendar2 = (props: Calendar2Props) => {\n  const {\n    calendars,\n    events: data = [],\n    now,\n    onSelectEvent,\n    errorMessage,\n    status,\n    timeZone = 'UTC',\n    weekStartsOn = 0,\n  } = props\n  const state = getBlockState(status, data)\n  const events = state ? [] : data\n  const today = getDay(now, timeZone)\n  const [anchor, setAnchor] = useState(today)\n  const [selectedId, setSelectedId] = useState<string | undefined>(\n    () =>\n      [...events]\n        .filter((event) => !event.allDay && (event.end ?? event.start) > now)\n        .sort((a, b) => a.start.getTime() - b.start.getTime())[0]?.id,\n  )\n\n  const container = useRef<HTMLDivElement>(null)\n\n  const days = getWeekDays(anchor, weekStartsOn)\n  const selected = events.find((event) => event.id === selectedId)\n  const weekEnd = addDays(days[6], 1)\n  const meetings = events.filter(\n    (event) =>\n      !event.allDay &&\n      event.end !== undefined &&\n      getDay(event.start, timeZone) >= days[0] &&\n      getDay(event.start, timeZone) < weekEnd,\n  )\n  const bookedMinutes = meetings.reduce(\n    (sum, event) =>\n      sum + ((event.end ?? event.start).getTime() - event.start.getTime()) / 60_000,\n    0,\n  )\n\n  const closeDetails = () => {\n    container.current\n      ?.querySelector<HTMLElement>(`[data-event-id=\"${selectedId}\"]`)\n      ?.focus()\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={formatDayRange(days[0], days[6])}\n          description={\n            state ? (\n              <BlockStateText />\n            ) : meetings.length === 0 ? (\n              'Nothing booked this week.'\n            ) : (\n              `${meetings.length} ${meetings.length === 1 ? 'meeting' : 'meetings'} taking ${formatDuration(new Date(0), new Date(bookedMinutes * 60_000))} this week.`\n            )\n          }\n          onToday={() => setAnchor(today)}\n          onPrevious={() => setAnchor(addDays(anchor, -7))}\n          onNext={() => setAnchor(addDays(anchor, 7))}\n          previousLabel='Previous week'\n          nextLabel='Next week'\n        />\n        <div ref={container} className='grid gap-6 @5xl:grid-cols-[minmax(0,1fr)_17rem]'>\n          <CalendarWeekView\n            days={days}\n            events={events}\n            now={now}\n            onSelectEvent={(event) => {\n              setSelectedId(event.id)\n              onSelectEvent?.(event)\n            }}\n            selectedEventId={selectedId}\n            timeZone={timeZone}\n            minColumnWidth='5.5rem'\n            className='h-[30rem]'\n          />\n          <div className='min-w-0 border-t pt-4 @5xl:border-t-0 @5xl:border-l @5xl:pt-0 @5xl:pl-6'>\n            {selected ? (\n              <CalendarEventDetails\n                event={selected}\n                timeZone={timeZone}\n                onClose={closeDetails}\n              />\n            ) : (\n              !state && (\n                <p className='text-muted-foreground text-sm'>\n                  Select an event to see its details.\n                </p>\n              )\n            )}\n          </div>\n        </div>\n        {!state && <CalendarLegend calendars={calendars} />}\n      </section>\n    </BlockStateProvider>\n  )\n}\n\nexport { Calendar2, exampleProps as calendar2ExampleProps, type Calendar2Props }\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/calendar/calendar-02.tsx"
    }
  ],
  "meta": {
    "shows": "A week on an hour axis that opens at working hours, with all-day events on top and the selected event's details.",
    "size": "full",
    "usedWith": [
      "calendar-01",
      "calendar-04"
    ],
    "component": "Calendar2",
    "props": "{ calendars: { color: string; name: string }[]; events?: { 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 }[]; now: Date; onSelectEvent?: (event: { 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; timeZone?: string; weekStartsOn?: 0 | 1; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
