{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "details-sidebar",
  "title": "Details Sidebar",
  "description": "The right context panel: the selected event's details, event search and useful shortcuts.",
  "dependencies": [
    "date-fns",
    "lucide-react"
  ],
  "registryDependencies": [
    "@calendarcn/calendar-core",
    "@calendarcn/event-details",
    "@calendarcn/sidebar-overlay",
    "button",
    "kbd",
    "sidebar",
    "tooltip"
  ],
  "files": [
    {
      "path": "src/components/details-sidebar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowLeft, CalendarSearch, PanelRightIcon, X } from \"lucide-react\";\nimport {\n  addDays,\n  format,\n  isBefore,\n  isSameYear,\n  isToday,\n  isTomorrow,\n  startOfDay,\n} from \"date-fns\";\n\nimport { cn } from \"@/lib/utils\";\nimport { eventColorStyles } from \"@/components/calendar-event-item\";\nimport { useCalendar, useCalendarConfig } from \"@/components/calendar-provider\";\nimport type { DetailedCalendarEvent } from \"@/components/calendar-types\";\nimport { EventDetailPanel } from \"@/components/event-detail-panel\";\nimport { useEventTitleFocus } from \"@/components/event-title-focus-context\";\nimport {\n  CALENDAR_SIDEBAR_COLORS_CLASS,\n  SidebarOverlay,\n} from \"@/components/sidebar-overlay\";\nimport { Button } from \"@/components/ui/button\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport {\n  SidebarContent,\n  SidebarGroup,\n  SidebarGroupContent,\n  SidebarGroupLabel,\n  SidebarHeader,\n  useSidebar,\n} from \"@/components/ui/sidebar\";\nimport {\n  Tooltip,\n  TooltipContent,\n  TooltipTrigger,\n} from \"@/components/ui/tooltip\";\nimport { resolveEventColor } from \"@/lib/event-utils\";\nimport { expandRecurringEvents } from \"@/lib/recurrence\";\nimport { formatDuration } from \"@/lib/time-input\";\n\n/**\n * Width of the context panel, inline or as an overlay: Notion Calendar's\n * 308px inside, plus the 1px border. Set it as `--sidebar-width` on the\n * `SidebarProvider` around the panel.\n */\nexport const CONTEXT_PANEL_WIDTH = \"309px\";\n\n/** Muted text color the context panel uses for labels and placeholders */\nconst PANEL_MUTED_FOREGROUND = \"#C7C5C1\";\n\n/**\n * Days before and after today the event search lists a repeating event's\n * dates for: a year either side\n */\nconst SEARCH_RANGE_DAYS = 365;\n\n/** A shortcut the context panel lists while no event is selected */\nexport interface DetailsSidebarShortcut {\n  label: string;\n  /** Keys pressed together, each shown as a key cap */\n  keys: string[];\n  /** Not built yet: a \"Soon\" badge is shown in place of its keys */\n  soon?: boolean;\n}\n\n/**\n * Notion Calendar's \"Useful shortcuts\", the panel's default list. The ones\n * nothing handles yet are marked `soon`\n */\nexport const USEFUL_SHORTCUTS: DetailsSidebarShortcut[] = [\n  { label: \"Command menu\", keys: [\"⌘\", \"K\"] },\n  { label: \"Menu bar calendar\", keys: [\"control\", \"⌘\", \"K\"], soon: true },\n  { label: \"Toggle sidebar\", keys: [\"⌘\", \"/\"] },\n  { label: \"Show teammate calendar\", keys: [\"P\"], soon: true },\n  { label: \"Go to date\", keys: [\".\"], soon: true },\n  { label: \"All keyboard shortcuts\", keys: [\"?\"], soon: true },\n];\n\n/** \"Soon\" badge of a listed shortcut that isn't built yet, as in the command menu */\nconst SOON_BADGE = (\n  <span className=\"bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px] leading-none font-medium\">\n    Soon\n  </span>\n);\n\ninterface DetailsSidebarProps extends React.ComponentProps<\"div\"> {\n  /** Render as a modal sheet instead of an inline column (phones and tablets) */\n  overlay?: boolean;\n  /** Shortcuts listed while no event is selected or searched */\n  shortcuts?: DetailsSidebarShortcut[];\n}\n\ninterface DateGroup {\n  key: string;\n  label: string;\n  isToday: boolean;\n  events: DetailedCalendarEvent[];\n}\n\nfunction formatTimeRange(event: DetailedCalendarEvent): string {\n  if (event.isAllDay) {\n    return \"All day\";\n  }\n  const startPeriod = format(event.start, \"a\");\n  const endPeriod = format(event.end, \"a\");\n  const endStr = format(event.end, \"h:mm a\").replace(\":00 \", \" \");\n\n  if (startPeriod === endPeriod) {\n    const startStr = format(event.start, \"h:mm\").replace(\":00\", \"\");\n    return `${startStr}\\u2013${endStr}`;\n  }\n\n  const startStr = format(event.start, \"h:mm a\").replace(\":00 \", \" \");\n  return `${startStr}\\u2013${endStr}`;\n}\n\nfunction formatDateHeader(date: Date): {\n  label: string;\n  isTodayGroup: boolean;\n} {\n  if (isToday(date)) {\n    return { label: \"Today\", isTodayGroup: true };\n  }\n  if (isTomorrow(date)) {\n    return { label: \"Tomorrow\", isTodayGroup: false };\n  }\n  if (isSameYear(date, new Date())) {\n    return { label: format(date, \"EEE MMM d\"), isTodayGroup: false };\n  }\n  return { label: format(date, \"EEE MMM d, yyyy\"), isTodayGroup: false };\n}\n\nfunction groupEventsByDate(events: DetailedCalendarEvent[]): DateGroup[] {\n  const grouped = new Map<string, DetailedCalendarEvent[]>();\n\n  for (const event of events) {\n    const dayKey = format(startOfDay(event.start), \"yyyy-MM-dd\");\n    const existing = grouped.get(dayKey);\n    if (existing) {\n      existing.push(event);\n    } else {\n      grouped.set(dayKey, [event]);\n    }\n  }\n\n  const groups: DateGroup[] = [];\n  for (const [key, groupEvents] of grouped) {\n    const date = groupEvents[0].start;\n    const { label, isTodayGroup } = formatDateHeader(date);\n    const sorted = groupEvents.sort(\n      (a, b) => a.start.getTime() - b.start.getTime(),\n    );\n    groups.push({ key, label, isToday: isTodayGroup, events: sorted });\n  }\n\n  return groups.sort((a, b) => a.key.localeCompare(b.key));\n}\n\n/**\n * Notion Calendar's context panel, on the right: the selected event's\n * details, event search, and useful shortcuts when nothing is selected.\n * Reads the events and the selection from the nearest `CalendarProvider`;\n * its open state is shadcn/ui's `SidebarProvider` (`useSidebar()`), with\n * `--sidebar-width` set to `CONTEXT_PANEL_WIDTH`.\n */\nexport function DetailsSidebar({\n  overlay = false,\n  shortcuts = USEFUL_SHORTCUTS,\n  className,\n  ...props\n}: DetailsSidebarProps) {\n  const {\n    events,\n    selectedEvent,\n    updateEvent,\n    previousInSeries,\n    nextInSeries,\n    showSeriesOccurrence,\n    deleteEvent,\n    duplicateEvent,\n    copyEvent,\n    cutEvent,\n  } = useCalendar<DetailedCalendarEvent>();\n  const {\n    toggleSidebar,\n    state,\n    open,\n    setOpen,\n    openMobile,\n    setOpenMobile,\n    isMobile,\n  } = useSidebar();\n  // shadcn keeps a separate open state for phones; follow whichever is active\n  const panelOpen = isMobile ? openMobile : open;\n  const setPanelOpen = isMobile ? setOpenMobile : setOpen;\n  const { pendingEventId, clearPending } = useEventTitleFocus();\n  const [searchQuery, setSearchQuery] = React.useState(\"\");\n  const [debouncedQuery, setDebouncedQuery] = React.useState(\"\");\n  const [searchSelectedEvent, setSearchSelectedEvent] =\n    React.useState<DetailedCalendarEvent | null>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  const isSearching = searchQuery.trim().length > 0;\n  const isLoadingResults = isSearching && searchQuery !== debouncedQuery;\n\n  React.useEffect(() => {\n    if (!isSearching) {\n      setDebouncedQuery(\"\");\n      return;\n    }\n    const timer = setTimeout(() => {\n      setDebouncedQuery(searchQuery);\n    }, 400);\n    return () => clearTimeout(timer);\n  }, [searchQuery, isSearching]);\n\n  const resolvedSearchEvent = React.useMemo(() => {\n    if (!searchSelectedEvent) return null;\n    return (\n      events.find((e) => e.id === searchSelectedEvent.id) ?? searchSelectedEvent\n    );\n  }, [events, searchSelectedEvent]);\n\n  React.useEffect(() => {\n    if (selectedEvent) {\n      setSearchSelectedEvent(null);\n    }\n  }, [selectedEvent]);\n\n  const searchResults = React.useMemo(() => {\n    if (!debouncedQuery.trim()) {\n      return [];\n    }\n    const query = debouncedQuery.trim().toLowerCase();\n    // A repeating event is listed on each of its dates within a year of\n    // today. Expanded before matching, so an edited date keeps its own title\n    const today = startOfDay(new Date());\n    const occurrences = expandRecurringEvents(events, {\n      start: addDays(today, -SEARCH_RANGE_DAYS),\n      end: addDays(today, SEARCH_RANGE_DAYS + 1),\n    });\n    return occurrences.filter((event) =>\n      event.title.toLowerCase().includes(query),\n    );\n  }, [events, debouncedQuery]);\n\n  const { pastGroups, todayGroup, futureGroups } = React.useMemo(() => {\n    const allGroups = groupEventsByDate(searchResults);\n    const now = new Date();\n    const todayStart = startOfDay(now);\n\n    const past: DateGroup[] = [];\n    let today: DateGroup | null = null;\n    const future: DateGroup[] = [];\n\n    for (const group of allGroups) {\n      if (group.isToday) {\n        today = group;\n        continue;\n      }\n      const groupDate = new Date(group.key);\n      if (isBefore(groupDate, todayStart)) {\n        past.push(group);\n        continue;\n      }\n      future.push(group);\n    }\n\n    return { pastGroups: past, todayGroup: today, futureGroups: future };\n  }, [searchResults]);\n\n  const hasUpcomingResults = todayGroup !== null || futureGroups.length > 0;\n\n  const onPrevWeek = previousInSeries\n    ? () => showSeriesOccurrence(previousInSeries)\n    : undefined;\n  const onNextWeek = nextInSeries\n    ? () => showSeriesOccurrence(nextInSeries)\n    : undefined;\n\n  /**\n   * The \"...\" menu's actions for the event the panel shows. Deleting or\n   * cutting a search pick also leaves the pick, which the provider doesn't\n   * select\n   */\n  const getEventActions = (eventId: string) => ({\n    onCut: () => {\n      cutEvent(eventId);\n      setSearchSelectedEvent(null);\n    },\n    onCopy: () => copyEvent(eventId),\n    onDuplicate: () => duplicateEvent(eventId),\n    onDelete: () => {\n      deleteEvent(eventId);\n      setSearchSelectedEvent(null);\n    },\n  });\n\n  const panel = (\n    <>\n      <SidebarHeader className=\"h-14 justify-center px-4\">\n        <div className=\"flex items-center gap-2\">\n          {selectedEvent ? (\n            <div className=\"flex-1\" />\n          ) : resolvedSearchEvent ? (\n            <>\n              <Button\n                variant=\"ghost\"\n                className=\"-ml-2 h-7 gap-2 px-2 has-[>svg]:px-2 text-xs text-[#91908F] justify-start\"\n                onClick={() => setSearchSelectedEvent(null)}\n              >\n                <ArrowLeft className=\"size-4\" />\n                Search\n              </Button>\n              <div className=\"flex-1\" />\n            </>\n          ) : (\n            <div\n              className=\"group/search flex flex-1 cursor-text items-center gap-2 rounded-sm border border-transparent px-1 hover:border-[#F5F5F5] hover:bg-[#F5F5F5] dark:hover:border-[#373737] dark:hover:bg-transparent has-[:focus]:border-[#F5F5F5] has-[:focus]:bg-[#F5F5F5] dark:has-[:focus]:border-[#242424] dark:has-[:focus]:bg-[#242424]\"\n              onClick={() => inputRef.current?.focus()}\n            >\n              <CalendarSearch className=\"size-4 shrink-0 text-[#C7C5C1] dark:text-[#595959]\" />\n              <input\n                ref={inputRef}\n                type=\"text\"\n                placeholder=\"Search events\"\n                value={searchQuery}\n                onChange={(e) => setSearchQuery(e.target.value)}\n                className=\"text-foreground placeholder:text-muted-foreground h-7 w-full border-none bg-transparent p-0 text-xs outline-none\"\n              />\n              {isSearching && (\n                <Button\n                  variant=\"ghost\"\n                  size=\"icon\"\n                  className=\"size-7 shrink-0 opacity-0 transition-opacity group-hover/search:opacity-100 group-has-[:focus]/search:opacity-100\"\n                  onClick={(e) => {\n                    e.stopPropagation();\n                    setSearchQuery(\"\");\n                    inputRef.current?.focus();\n                  }}\n                >\n                  <X className=\"size-4\" />\n                </Button>\n              )}\n            </div>\n          )}\n          <Tooltip>\n            <TooltipTrigger asChild>\n              <Button\n                variant=\"ghost\"\n                size=\"icon\"\n                className=\"size-7 shrink-0\"\n                onClick={toggleSidebar}\n              >\n                <PanelRightIcon className=\"size-4\" />\n              </Button>\n            </TooltipTrigger>\n            <TooltipContent side=\"bottom\">\n              Close context panel <Kbd className=\"ml-1\">/</Kbd>\n            </TooltipContent>\n          </Tooltip>\n        </div>\n      </SidebarHeader>\n      <SidebarContent className=\"gap-2\">\n        {selectedEvent ? (\n          <EventDetailPanel\n            event={selectedEvent}\n            onEventChange={updateEvent}\n            onPrevWeek={onPrevWeek}\n            onNextWeek={onNextWeek}\n            {...getEventActions(selectedEvent.id)}\n            autoFocusTitle={panelOpen && pendingEventId === selectedEvent.id}\n            onTitleAutoFocused={clearPending}\n          />\n        ) : resolvedSearchEvent ? (\n          <EventDetailPanel\n            event={resolvedSearchEvent}\n            onEventChange={updateEvent}\n            onPrevWeek={onPrevWeek}\n            onNextWeek={onNextWeek}\n            {...getEventActions(resolvedSearchEvent.id)}\n          />\n        ) : isLoadingResults ? (\n          <div className=\"px-4 pl-8 pt-8\">\n            <p className=\"text-[#ABABA9] dark:text-[#7C7C7C] text-xs\">\n              Searching\n              <AnimatedDots />\n            </p>\n          </div>\n        ) : isSearching ? (\n          <div className=\"flex flex-col pb-16\">\n            {pastGroups.map((group) => (\n              <DateGroupSection\n                key={group.key}\n                group={group}\n                isPast\n                onEventClick={setSearchSelectedEvent}\n              />\n            ))}\n            <div className=\"px-4 pt-5\">\n              <p className=\"-ml-1 text-[#E8533E] text-xs font-semibold pb-3\">\n                Today\n              </p>\n              {todayGroup && (\n                <div className=\"flex flex-col\">\n                  {todayGroup.events.map((event) => (\n                    <SearchResultItem\n                      key={event.id}\n                      event={event}\n                      onClick={setSearchSelectedEvent}\n                    />\n                  ))}\n                </div>\n              )}\n              {!hasUpcomingResults && (\n                <p className=\"text-[#ABABA9] dark:text-[#7F7F7F] pl-4 pt-1 text-xs\">\n                  No upcoming results\n                </p>\n              )}\n            </div>\n            {futureGroups.map((group) => (\n              <DateGroupSection\n                key={group.key}\n                group={group}\n                onEventClick={setSearchSelectedEvent}\n              />\n            ))}\n          </div>\n        ) : (\n          <SidebarGroup className=\"px-3 pt-6\">\n            <SidebarGroupLabel className=\"text-foreground text-xs font-semibold px-0\">\n              Useful shortcuts\n            </SidebarGroupLabel>\n            <SidebarGroupContent>\n              <div className=\"flex flex-col\">\n                {shortcuts.map((shortcut) => (\n                  <ShortcutRow\n                    key={shortcut.label}\n                    label={shortcut.label}\n                    soon={shortcut.soon}\n                  >\n                    {shortcut.keys.map((key) => (\n                      <Kbd key={key}>{key}</Kbd>\n                    ))}\n                  </ShortcutRow>\n                ))}\n              </div>\n            </SidebarGroupContent>\n          </SidebarGroup>\n        )}\n      </SidebarContent>\n    </>\n  );\n\n  if (overlay) {\n    return (\n      <SidebarOverlay\n        open={panelOpen}\n        onOpenChange={setPanelOpen}\n        side=\"right\"\n        title=\"Context panel\"\n        description=\"Event details, event search and useful shortcuts.\"\n        className=\"!bg-calendar-context-panel\"\n        style={\n          {\n            \"--sidebar-width\": CONTEXT_PANEL_WIDTH,\n            \"--muted-foreground\": PANEL_MUTED_FOREGROUND,\n          } as React.CSSProperties\n        }\n      >\n        {panel}\n      </SidebarOverlay>\n    );\n  }\n\n  // shadcn's Sidebar markup for side=\"right\", collapsible=\"offcanvas\", without\n  // its slide transition: the panel opens and closes at once\n  return (\n    <div\n      className=\"group peer text-sidebar-foreground hidden md:block\"\n      data-state={state}\n      data-collapsible={state === \"collapsed\" ? \"offcanvas\" : \"\"}\n      data-variant=\"sidebar\"\n      data-side=\"right\"\n      data-slot=\"sidebar\"\n    >\n      {/* Takes the panel's width in the page's flex row */}\n      <div\n        data-slot=\"sidebar-gap\"\n        className=\"relative w-(--sidebar-width) rotate-180 bg-transparent group-data-[collapsible=offcanvas]:w-0\"\n      />\n      <div\n        data-slot=\"sidebar-container\"\n        className={cn(\n          CALENDAR_SIDEBAR_COLORS_CLASS,\n          \"bg-calendar-context-panel text-sidebar-foreground fixed inset-y-0 right-0 z-10 hidden h-svh w-(--sidebar-width) border-l md:flex group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]\",\n          className,\n        )}\n        style={\n          {\n            \"--muted-foreground\": PANEL_MUTED_FOREGROUND,\n          } as React.CSSProperties\n        }\n        {...props}\n      >\n        <div\n          data-sidebar=\"sidebar\"\n          data-slot=\"sidebar-inner\"\n          className=\"bg-calendar-context-panel flex h-full w-full flex-col\"\n        >\n          {panel}\n        </div>\n      </div>\n    </div>\n  );\n}\n\nfunction DateGroupSection({\n  group,\n  isPast = false,\n  onEventClick,\n}: {\n  group: DateGroup;\n  isPast?: boolean;\n  onEventClick?: (event: DetailedCalendarEvent) => void;\n}) {\n  return (\n    <div className=\"px-4 pt-5\">\n      <p\n        className={cn(\n          \"-ml-1 text-xs font-semibold pb-3\",\n          group.isToday ? \"text-[#E8533E]\" : \"text-foreground\",\n        )}\n      >\n        {group.label}\n      </p>\n      <div className=\"flex flex-col\">\n        {group.events.map((event) => (\n          <SearchResultItem\n            key={event.id}\n            event={event}\n            isPast={isPast}\n            onClick={onEventClick}\n          />\n        ))}\n      </div>\n    </div>\n  );\n}\n\n/** Color tokens for search result items by temporal state */\nconst SEARCH_RESULT_COLORS = {\n  future: {\n    title: \"text-[#32302C] dark:text-[#D4D4D4]\",\n    time: \"text-[#787774] dark:text-[#7F7F7F]\",\n    duration: \"text-[#ABABA9] dark:text-[#5A5A5A]\",\n    hover: \"hover:bg-[#F5F5F5] dark:hover:bg-[#252525]\",\n  },\n  past: {\n    title: \"text-[#989795] dark:text-[#777]\",\n    time: \"text-[#BBBBB9] dark:text-[#4C4C4C]\",\n    duration: \"text-[#D5D5D4] dark:text-[#3A3A3A]\",\n    hover: \"hover:bg-[#FAFAFA] dark:hover:bg-[#1F1F1F]\",\n  },\n} as const;\n\n/**\n * Sequential dot fill animation.\n * Steps: fill dot 0 → fill dot 1 → fill dot 2 → unfill dot 0 → unfill dot 1 → unfill dot 2\n * Each dot is either 10% or 100% opacity based on the current step.\n */\nconst DOT_STEP_INTERVAL_MS = 300;\nconst DOT_STEPS = [\n  [false, false, false],\n  [true, false, false],\n  [true, true, false],\n  [true, true, true],\n  [false, true, true],\n  [false, false, true],\n] as const;\n\nfunction AnimatedDots() {\n  const [step, setStep] = React.useState(0);\n\n  React.useEffect(() => {\n    const interval = setInterval(() => {\n      setStep((prev) => (prev + 1) % DOT_STEPS.length);\n    }, DOT_STEP_INTERVAL_MS);\n    return () => clearInterval(interval);\n  }, []);\n\n  const filled = DOT_STEPS[step];\n\n  return (\n    <span className=\"ml-1 inline-flex items-center gap-0.5\">\n      {[0, 1, 2].map((i) => (\n        <span\n          key={i}\n          className=\"inline-block size-0.5 rounded-full bg-[#ABABA9] dark:bg-[#7C7C7C] transition-opacity duration-200\"\n          style={{ opacity: filled[i] ? 1 : 0.1 }}\n        />\n      ))}\n    </span>\n  );\n}\n\nfunction SearchResultItem({\n  event,\n  isPast = false,\n  onClick,\n}: {\n  event: DetailedCalendarEvent;\n  isPast?: boolean;\n  onClick?: (event: DetailedCalendarEvent) => void;\n}) {\n  const { calendars } = useCalendarConfig();\n  const timeRange = formatTimeRange(event);\n  const duration = event.isAllDay ? \"\" : formatDuration(event.start, event.end);\n  const colors = isPast\n    ? SEARCH_RESULT_COLORS.past\n    : SEARCH_RESULT_COLORS.future;\n\n  return (\n    <div\n      className={cn(\n        \"-mx-1 flex cursor-default items-start gap-2.5 rounded-sm px-1 py-2\",\n        colors.hover,\n      )}\n      onClick={() => onClick?.(event)}\n    >\n      <div\n        className={cn(\n          \"-mt-1 -mb-1 w-1 shrink-0 self-stretch rounded-full\",\n          eventColorStyles[resolveEventColor(event, calendars)].border,\n          isPast && \"opacity-40\",\n        )}\n      />\n      <div className=\"flex min-w-0 flex-col gap-0.5\">\n        <p\n          className={cn(\n            \"truncate text-sm font-medium leading-snug\",\n            colors.title,\n          )}\n        >\n          {event.title}\n        </p>\n        <p className=\"text-sm\">\n          <span className={colors.time}>{timeRange}</span>\n          {duration && <span className={colors.duration}> {duration}</span>}\n        </p>\n      </div>\n    </div>\n  );\n}\n\nfunction ShortcutRow({\n  label,\n  soon,\n  children,\n}: {\n  label: string;\n  /** Not built yet: a \"Soon\" badge replaces the keys */\n  soon?: boolean;\n  children: React.ReactNode;\n}) {\n  return (\n    <div className=\"text-muted-foreground flex items-center justify-between py-1 text-xs\">\n      <span>{label}</span>\n      <div className=\"flex items-center gap-1\">\n        {soon ? SOON_BADGE : children}\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}