{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "calendar-list",
  "title": "Calendar List",
  "description": "The calendars grouped by account, each with its color and a button to show or hide it.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@calendarcn/calendar-core",
    "collapsible",
    "sidebar"
  ],
  "files": [
    {
      "path": "src/components/calendar-list.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { ChevronRight, Eye, EyeOff, Rss } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useControllableState } from \"@/hooks/use-controllable-state\";\nimport { useCalendarConfig } from \"@/components/calendar-provider\";\nimport type { CalendarInfo, EventColor } from \"@/components/calendar-types\";\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from \"@/components/ui/collapsible\";\nimport {\n  SidebarGroup,\n  SidebarGroupContent,\n  SidebarGroupLabel,\n  SidebarMenu,\n  SidebarMenuButton,\n  SidebarMenuItem,\n  SidebarSeparator,\n} from \"@/components/ui/sidebar\";\nimport { groupCalendarsByEmail } from \"@/lib/event-utils\";\n\n/** Swatch color of each calendar color */\nconst CALENDAR_SWATCH_CLASSES: Record<EventColor, string> = {\n  red: \"bg-event-red\",\n  orange: \"bg-event-orange\",\n  yellow: \"bg-event-yellow\",\n  green: \"bg-event-green\",\n  blue: \"bg-event-blue\",\n  purple: \"bg-event-purple\",\n  gray: \"bg-event-gray\",\n};\n\n/** Hidden calendars when the list owns them: none */\nconst NO_HIDDEN_CALENDARS: string[] = [];\n\n/** Label of the group of calendars that have no account `email` */\nconst NO_ACCOUNT_LABEL = \"Calendars\";\n\ninterface CalendarListProps {\n  /**\n   * Calendars to list, grouped under their account `email`. Defaults to the\n   * `calendars` of the nearest `CalendarProvider`.\n   */\n  calendars?: CalendarInfo[];\n  /** Ids of the hidden calendars (controlled) */\n  hiddenCalendarIds?: string[];\n  /** Ids of the calendars hidden at first (uncontrolled) */\n  defaultHiddenCalendarIds?: string[];\n  /** Called with the new hidden ids when a calendar is shown or hidden */\n  onHiddenCalendarIdsChange?: (hiddenCalendarIds: string[]) => void;\n}\n\n/**\n * The sidebar's calendars, one collapsible group per account, with an eye\n * button to show or hide each. Hiding only dims the row: filter your events\n * with `onHiddenCalendarIdsChange` to take them off the calendar.\n */\nexport function CalendarList({\n  calendars: calendarsProp,\n  hiddenCalendarIds: hiddenCalendarIdsProp,\n  defaultHiddenCalendarIds = NO_HIDDEN_CALENDARS,\n  onHiddenCalendarIdsChange,\n}: CalendarListProps) {\n  const config = useCalendarConfig();\n  const calendars = calendarsProp ?? config.calendars;\n  const [hiddenCalendarIds, setHiddenCalendarIds] = useControllableState({\n    prop: hiddenCalendarIdsProp,\n    defaultProp: defaultHiddenCalendarIds,\n    onChange: onHiddenCalendarIdsChange,\n  });\n\n  const groups = React.useMemo(\n    () => groupCalendarsByEmail(calendars),\n    [calendars],\n  );\n\n  const toggleVisibility = (calendarId: string) => {\n    setHiddenCalendarIds((prev) =>\n      prev.includes(calendarId)\n        ? prev.filter((id) => id !== calendarId)\n        : [...prev, calendarId],\n    );\n  };\n\n  return (\n    <>\n      {groups.map((group, index) => (\n        <React.Fragment key={group.email ?? NO_ACCOUNT_LABEL}>\n          <SidebarGroup className=\"py-0\">\n            <Collapsible defaultOpen className=\"group/collapsible\">\n              <SidebarGroupLabel\n                asChild\n                className=\"group/label text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground w-full rounded-sm text-xs\"\n              >\n                <CollapsibleTrigger>\n                  <span className=\"truncate\">\n                    {group.email ?? NO_ACCOUNT_LABEL}\n                  </span>\n                  {/* Open state: Radix sets data-state on the root, Base UI data-panel-open on the trigger */}\n                  <ChevronRight className=\"ml-auto shrink-0 opacity-0 transition-transform group-hover/label:opacity-100 group-data-[state=open]/collapsible:rotate-90 group-data-panel-open/label:rotate-90\" />\n                </CollapsibleTrigger>\n              </SidebarGroupLabel>\n              <CollapsibleContent>\n                <SidebarGroupContent>\n                  <SidebarMenu className=\"gap-0\">\n                    {group.calendars.map((calendar) => {\n                      const isVisible = !hiddenCalendarIds.includes(\n                        calendar.id,\n                      );\n                      return (\n                        <SidebarMenuItem\n                          key={calendar.id}\n                          className=\"group/calendar-item\"\n                        >\n                          <SidebarMenuButton className=\"rounded-sm pr-1\">\n                            <div\n                              className={cn(\n                                \"size-3 shrink-0 flex items-center justify-center rounded-xs\",\n                                CALENDAR_SWATCH_CLASSES[calendar.color],\n                                !isVisible && \"opacity-40\",\n                              )}\n                            >\n                              {/* Icon sizes are !important: some shadcn/ui styles size every svg in a menu button */}\n                              {calendar.isSubscribed && (\n                                <Rss className=\"!size-2 text-white\" />\n                              )}\n                            </div>\n                            <span\n                              className={cn(\n                                \"flex-1 truncate text-xs text-sidebar-foreground\",\n                                !isVisible && \"opacity-50\",\n                              )}\n                            >\n                              {calendar.name}\n                            </span>\n                            <span\n                              role=\"button\"\n                              tabIndex={0}\n                              aria-label={`${isVisible ? \"Hide\" : \"Show\"} ${calendar.name}`}\n                              className=\"inline-flex size-6 shrink-0 items-center justify-center rounded-sm opacity-0 hover:bg-sidebar-accent group-hover/calendar-item:opacity-100\"\n                              onClick={(e) => {\n                                e.stopPropagation();\n                                toggleVisibility(calendar.id);\n                              }}\n                              onKeyDown={(e) => {\n                                if (e.key === \"Enter\" || e.key === \" \") {\n                                  e.preventDefault();\n                                  e.stopPropagation();\n                                  toggleVisibility(calendar.id);\n                                }\n                              }}\n                            >\n                              {isVisible ? (\n                                <Eye className=\"!size-3.5 text-calendar-sidebar-muted-foreground\" />\n                              ) : (\n                                <EyeOff className=\"!size-3.5 text-calendar-sidebar-muted-foreground\" />\n                              )}\n                            </span>\n                          </SidebarMenuButton>\n                        </SidebarMenuItem>\n                      );\n                    })}\n                  </SidebarMenu>\n                </SidebarGroupContent>\n              </CollapsibleContent>\n            </Collapsible>\n          </SidebarGroup>\n          {index < groups.length - 1 && <SidebarSeparator className=\"mx-0\" />}\n        </React.Fragment>\n      ))}\n    </>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "cssVars": {
    "light": {
      "calendar-sidebar-muted-foreground": "#cfcfce"
    },
    "dark": {
      "calendar-sidebar-muted-foreground": "#555555"
    }
  },
  "type": "registry:component"
}