{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-shell",
  "title": "App Shell",
  "description": "Primitives for app shells built on the shadcn sidebar: navigation sections from data with active links, badges and collapsible child links, a brand link, a workspace switcher, sidebar and avatar user menus, a top bar, breadcrumbs, a search button with a keyboard shortcut, a notifications bell, a side panel with its header button, plan usage, a top navigation row, and a sidebar layout whose links stay in view while its content scrolls.",
  "registryDependencies": [
    "avatar",
    "breadcrumb",
    "button",
    "collapsible",
    "dropdown-menu",
    "kbd",
    "sheet",
    "sidebar",
    "tooltip",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/link.json",
    "https://www.dashboardblocks.com/r/radix/tag.json",
    "https://www.dashboardblocks.com/r/radix/page-header.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json",
    "https://www.dashboardblocks.com/r/radix/usage-meter.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/app-shell.tsx",
      "content": "'use client'\n\nimport { isPlainClick, Link } from '@/registry/components/dashboardblocks/link'\nimport { TabLinks } from '@/registry/components/dashboardblocks/page-header'\nimport { renderTag } from '@/registry/components/dashboardblocks/tag'\nimport {\n  PlanUsageShare,\n  UsageBar,\n  planUsageThresholds,\n} from '@/registry/components/dashboardblocks/usage-meter'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport {\n  Fragment,\n  type ReactNode,\n  useEffect,\n  useLayoutEffect,\n  useRef,\n  useState,\n  useSyncExternalStore,\n} from 'react'\n\nimport { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'\nimport {\n  Breadcrumb,\n  BreadcrumbItem,\n  BreadcrumbLink,\n  BreadcrumbList,\n  BreadcrumbPage,\n  BreadcrumbSeparator,\n} from '@/components/ui/breadcrumb'\nimport { Button, buttonVariants } from '@/components/ui/button'\nimport {\n  Collapsible,\n  CollapsibleContent,\n  CollapsibleTrigger,\n} from '@/components/ui/collapsible'\nimport {\n  DropdownMenu,\n  DropdownMenuContent,\n  DropdownMenuGroup,\n  DropdownMenuItem,\n  DropdownMenuLabel,\n  DropdownMenuSeparator,\n  DropdownMenuTrigger,\n} from '@/components/ui/dropdown-menu'\nimport { Kbd } from '@/components/ui/kbd'\nimport { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet'\nimport {\n  Sidebar,\n  SidebarContent,\n  SidebarFooter,\n  SidebarGroup,\n  SidebarGroupLabel,\n  SidebarHeader,\n  SidebarInset,\n  SidebarMenu,\n  SidebarMenuBadge,\n  SidebarMenuButton,\n  SidebarMenuItem,\n  SidebarMenuSub,\n  SidebarMenuSubButton,\n  SidebarMenuSubItem,\n  SidebarProvider,\n  SidebarTrigger,\n  useSidebar,\n} from '@/components/ui/sidebar'\nimport { TooltipProvider } from '@/components/ui/tooltip'\n\nimport { cn } from '@/lib/utils'\n\ninterface NavLink {\n  badge?: ReactNode\n  href: string\n  /** Shown before the title. */\n  icon?: ReactNode\n  title: string\n}\n\ninterface NavItem {\n  badge?: ReactNode\n  /** Leave out when the item only groups `items`. */\n  href?: string\n  icon: ReactNode\n  items?: NavLink[]\n  /** Makes the item a button that does something, such as opening search, in place of a link. */\n  onSelect?: () => void\n  title: string\n}\n\ninterface NavSection {\n  items: NavItem[]\n  label?: string\n}\n\nfunction useCloseMobileSidebar() {\n  const { isMobile, setOpenMobile } = useSidebar()\n  return () => {\n    if (isMobile) setOpenMobile(false)\n  }\n}\n\nfunction isActiveHref(href: string, pathname: string) {\n  if (href === pathname) return true\n  return href !== '/' && pathname.startsWith(`${href.replace(/\\/$/, '')}/`)\n}\n\nfunction getInitials(name: string) {\n  return name\n    .split(/\\s+/)\n    .filter(Boolean)\n    .slice(0, 2)\n    .map((part) => part[0]?.toUpperCase())\n    .join('')\n}\n\ninterface AppNavProps {\n  className?: string\n  pathname: string\n  sections: NavSection[]\n}\n\nfunction AppNav({ className, pathname, sections }: AppNavProps) {\n  return (\n    <TooltipProvider>\n      {sections.map((section, index) => (\n        <SidebarGroup key={section.label ?? index} className={className}>\n          {section.label && <SidebarGroupLabel>{section.label}</SidebarGroupLabel>}\n          <SidebarMenu>\n            {section.items.map((item) => (\n              <AppNavItem key={item.title} item={item} pathname={pathname} />\n            ))}\n          </SidebarMenu>\n        </SidebarGroup>\n      ))}\n    </TooltipProvider>\n  )\n}\n\nfunction useRailTooltip() {\n  const { isMobile } = useSidebar()\n  return (label: string) => (isMobile ? undefined : label)\n}\n\nfunction AppNavItem({ item, pathname }: { item: NavItem; pathname: string }) {\n  const { setOpen, state } = useSidebar()\n  const closeMobile = useCloseMobileSidebar()\n  const railTooltip = useRailTooltip()\n  const childActive =\n    item.items?.some((child) => isActiveHref(child.href, pathname)) ?? false\n  const [expanded, setExpanded] = useState(childActive)\n  const [wasChildActive, setWasChildActive] = useState(childActive)\n  if (childActive !== wasChildActive) {\n    setWasChildActive(childActive)\n    if (childActive) setExpanded(true)\n  }\n\n  if (!item.href && item.onSelect) {\n    const { onSelect } = item\n    return (\n      <SidebarMenuItem>\n        <SidebarMenuButton\n          tooltip={railTooltip(item.title)}\n          onClick={() => {\n            closeMobile()\n            onSelect()\n          }}\n        >\n          {item.icon}\n          <span>{item.title}</span>\n        </SidebarMenuButton>\n      </SidebarMenuItem>\n    )\n  }\n\n  if (!item.items?.length) {\n    const active = item.href !== undefined && isActiveHref(item.href, pathname)\n    return (\n      <SidebarMenuItem>\n        <SidebarMenuButton isActive={active} tooltip={railTooltip(item.title)} asChild>\n          <Link\n            href={item.href}\n            aria-current={item.href === pathname ? 'page' : undefined}\n            onClick={closeMobile}\n          >\n            {item.icon}\n            <span>{item.title}</span>\n          </Link>\n        </SidebarMenuButton>\n        {item.badge !== undefined && (\n          <SidebarMenuBadge>{renderTag(item.badge)}</SidebarMenuBadge>\n        )}\n      </SidebarMenuItem>\n    )\n  }\n\n  return (\n    <Collapsible\n      open={expanded}\n      onOpenChange={setExpanded}\n      className='group/collapsible'\n      asChild\n    >\n      <SidebarMenuItem>\n        <CollapsibleTrigger asChild>\n          <SidebarMenuButton\n            tooltip={railTooltip(item.title)}\n            onClick={() => state === 'collapsed' && setOpen(true)}\n          >\n            {item.icon}\n            <span>{item.title}</span>\n            <IconPlaceholder\n              lucide='ChevronRightIcon'\n              tabler='IconChevronRight'\n              hugeicons='ArrowRight01Icon'\n              phosphor='CaretRightIcon'\n              remixicon='RiArrowRightSLine'\n              className='ml-auto transition-transform duration-200 group-data-open/collapsible:rotate-90'\n            />\n          </SidebarMenuButton>\n        </CollapsibleTrigger>\n        <CollapsibleContent>\n          <SidebarMenuSub>\n            {item.items.map((child) => (\n              <SidebarMenuSubItem key={child.href}>\n                <SidebarMenuSubButton\n                  isActive={isActiveHref(child.href, pathname)}\n                  aria-current={child.href === pathname ? 'page' : undefined}\n                  asChild\n                >\n                  <Link href={child.href} onClick={closeMobile}>\n                    <span>{child.title}</span>\n                    {child.badge !== undefined && (\n                      <span className='ml-auto flex'>{renderTag(child.badge)}</span>\n                    )}\n                  </Link>\n                </SidebarMenuSubButton>\n              </SidebarMenuSubItem>\n            ))}\n          </SidebarMenuSub>\n        </CollapsibleContent>\n      </SidebarMenuItem>\n    </Collapsible>\n  )\n}\n\ninterface AppBrandProps {\n  description?: ReactNode\n  href: string\n  logo: ReactNode\n  name: string\n}\n\nfunction AppBrand({ description, href, logo, name }: AppBrandProps) {\n  const closeMobile = useCloseMobileSidebar()\n  return (\n    <SidebarMenu>\n      <SidebarMenuItem>\n        <SidebarMenuButton size='lg' asChild>\n          <Link href={href} onClick={closeMobile}>\n            <BrandMark>{logo}</BrandMark>\n            <span className='grid flex-1 text-left text-sm leading-tight'>\n              <span className='truncate font-medium'>{name}</span>\n              {description && <span className='truncate text-xs'>{description}</span>}\n            </span>\n          </Link>\n        </SidebarMenuButton>\n      </SidebarMenuItem>\n    </SidebarMenu>\n  )\n}\n\nfunction BrandMark({ children, className }: { children: ReactNode; className?: string }) {\n  return (\n    <span\n      className={cn(\n        'bg-sidebar-primary text-sidebar-primary-foreground flex aspect-square size-8 shrink-0 items-center justify-center rounded-lg [&_svg]:size-4',\n        className,\n      )}\n    >\n      {children}\n    </span>\n  )\n}\n\ninterface Workspace {\n  id: string\n  logo: ReactNode\n  name: string\n  plan?: string\n}\n\ninterface WorkspaceSwitcherProps {\n  /** With one workspace and no `onCreate`, the header links here, such as the first page, instead of opening a menu with nothing to pick. */\n  href?: string\n  /** Adds a \"New workspace\" item. */\n  onCreate?: () => void\n  onValueChange: (id: string) => void\n  value: string\n  workspaces: Workspace[]\n}\n\nfunction WorkspaceSwitcher({\n  href,\n  onCreate,\n  onValueChange,\n  value,\n  workspaces,\n}: WorkspaceSwitcherProps) {\n  const { isMobile } = useSidebar()\n  const current = workspaces.find((workspace) => workspace.id === value) ?? workspaces[0]\n  if (!current) return null\n  if (href && workspaces.length === 1 && !onCreate)\n    return (\n      <AppBrand\n        description={current.plan}\n        href={href}\n        logo={current.logo}\n        name={current.name}\n      />\n    )\n\n  return (\n    <SidebarMenu>\n      <SidebarMenuItem>\n        <DropdownMenu modal={false}>\n          <DropdownMenuTrigger asChild>\n            <SidebarMenuButton size='lg' className='aria-expanded:bg-muted'>\n              <BrandMark>{current.logo}</BrandMark>\n              <span className='grid flex-1 text-left text-sm leading-tight'>\n                <span className='truncate font-medium'>{current.name}</span>\n                {current.plan && <span className='truncate text-xs'>{current.plan}</span>}\n              </span>\n              <IconPlaceholder\n                lucide='ChevronsUpDownIcon'\n                tabler='IconSelector'\n                hugeicons='UnfoldMoreIcon'\n                phosphor='CaretUpDownIcon'\n                remixicon='RiArrowUpDownLine'\n                className='ml-auto'\n              />\n            </SidebarMenuButton>\n          </DropdownMenuTrigger>\n          <DropdownMenuContent\n            className='min-w-56'\n            align='start'\n            side={isMobile ? 'bottom' : 'right'}\n          >\n            <DropdownMenuGroup>\n              <DropdownMenuLabel>Workspaces</DropdownMenuLabel>\n              {workspaces.map((workspace) => (\n                <DropdownMenuItem\n                  key={workspace.id}\n                  onClick={() => onValueChange(workspace.id)}\n                >\n                  <span className='flex size-6 shrink-0 items-center justify-center rounded-md border [&_svg]:size-3.5'>\n                    {workspace.logo}\n                  </span>\n                  {workspace.name}\n                  {workspace.id === current.id && (\n                    <>\n                      <span className='sr-only'>(current)</span>\n                      <IconPlaceholder\n                        lucide='CheckIcon'\n                        tabler='IconCheck'\n                        hugeicons='Tick02Icon'\n                        phosphor='CheckIcon'\n                        remixicon='RiCheckLine'\n                        className='ml-auto'\n                      />\n                    </>\n                  )}\n                </DropdownMenuItem>\n              ))}\n            </DropdownMenuGroup>\n            {onCreate && (\n              <>\n                <DropdownMenuSeparator />\n                <DropdownMenuItem onClick={onCreate}>\n                  <IconPlaceholder\n                    lucide='PlusIcon'\n                    tabler='IconPlus'\n                    hugeicons='PlusSignIcon'\n                    phosphor='PlusIcon'\n                    remixicon='RiAddLine'\n                  />\n                  New workspace\n                </DropdownMenuItem>\n              </>\n            )}\n          </DropdownMenuContent>\n        </DropdownMenu>\n      </SidebarMenuItem>\n    </SidebarMenu>\n  )\n}\n\ninterface AppUser {\n  avatar?: string\n  email: string\n  name: string\n}\n\ninterface UserMenuLink {\n  href: string\n  icon: ReactNode\n  label: string\n}\n\ntype AppTheme = 'dark' | 'light' | 'system'\n\ninterface ThemeChoice {\n  onValueChange: (theme: AppTheme) => void\n  /** `system` follows the device's setting. */\n  value: AppTheme\n}\n\ninterface UserMenuProps {\n  links: UserMenuLink[]\n  onSignOut: () => void\n  /** Adds a Light, Dark and System choice, such as `useTheme()` from next-themes. */\n  theme?: ThemeChoice\n  user: AppUser\n}\n\nconst themes: { icon: ReactNode; label: string; value: AppTheme }[] = [\n  {\n    icon: (\n      <IconPlaceholder\n        lucide='SunIcon'\n        tabler='IconSun'\n        hugeicons='Sun03Icon'\n        phosphor='SunIcon'\n        remixicon='RiSunLine'\n        className='size-3.5'\n      />\n    ),\n    label: 'Light',\n    value: 'light',\n  },\n  {\n    icon: (\n      <IconPlaceholder\n        lucide='MoonIcon'\n        tabler='IconMoon'\n        hugeicons='Moon02Icon'\n        phosphor='MoonIcon'\n        remixicon='RiMoonLine'\n        className='size-3.5'\n      />\n    ),\n    label: 'Dark',\n    value: 'dark',\n  },\n  {\n    icon: (\n      <IconPlaceholder\n        lucide='MonitorIcon'\n        tabler='IconDeviceDesktop'\n        hugeicons='ComputerIcon'\n        phosphor='MonitorIcon'\n        remixicon='RiComputerLine'\n        className='size-3.5'\n      />\n    ),\n    label: 'System',\n    value: 'system',\n  },\n]\n\nfunction themeIndex(value: AppTheme) {\n  return Math.max(\n    0,\n    themes.findIndex((theme) => theme.value === value),\n  )\n}\n\nfunction pickedTheme(target: EventTarget | null, value: AppTheme) {\n  const picked =\n    target instanceof Element\n      ? target.closest<HTMLElement>('[data-app-theme]')?.dataset.appTheme\n      : undefined\n  return (\n    themes.find((theme) => theme.value === picked)?.value ??\n    themes[(themeIndex(value) + 1) % themes.length].value\n  )\n}\n\nconst themeMotion = { duration: 500, easing: 'cubic-bezier(0.65, 0, 0.35, 1)' }\n\nfunction themeIconStyle(index: number, position: number) {\n  return {\n    opacity: position === index ? 1 : 0,\n    rotate: `${(index - position) * 120}deg`,\n    scale: position === index ? 1 : 0.5,\n  }\n}\n\nfunction ThemeSwitch({ value }: { value: AppTheme }) {\n  const index = themeIndex(value)\n  const thumbRef = useRef<HTMLSpanElement>(null)\n  const shown = useRef(index)\n\n  // next-themes' `disableTransitionOnChange` turns off every CSS transition while the\n  // theme changes, so the switch moves with the Web Animations API instead.\n  useLayoutEffect(() => {\n    const from = shown.current\n    shown.current = index\n    const thumb = thumbRef.current\n    if (from === index || !thumb) return\n    if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return\n    thumb.animate(\n      {\n        transform: [`translateX(${from * 100}%)`, `translateX(${index * 100}%)`],\n      },\n      themeMotion,\n    )\n    Array.from(thumb.children).forEach((icon, position) => {\n      const start = themeIconStyle(from, position)\n      const end = themeIconStyle(index, position)\n      icon.animate(\n        {\n          opacity: [start.opacity, end.opacity],\n          rotate: [start.rotate, end.rotate],\n          scale: [start.scale, end.scale],\n        },\n        themeMotion,\n      )\n    })\n  }, [index])\n\n  return (\n    <span\n      aria-hidden\n      className='bg-muted relative ml-auto grid grid-cols-3 rounded-md p-0.5'\n    >\n      {themes.map((theme) => (\n        <span\n          key={theme.value}\n          data-app-theme={theme.value}\n          className='text-muted-foreground flex h-6 w-7 items-center justify-center'\n        >\n          {theme.icon}\n        </span>\n      ))}\n      <span\n        ref={thumbRef}\n        data-app-theme={value}\n        className='bg-background text-foreground dark:ring-input absolute inset-y-0.5 left-0.5 w-7 rounded-sm shadow-sm dark:ring-1'\n        style={{ transform: `translateX(${index * 100}%)` }}\n      >\n        {themes.map((theme, position) => (\n          <span\n            key={theme.value}\n            className='absolute inset-0 flex items-center justify-center'\n            style={themeIconStyle(index, position)}\n          >\n            {theme.icon}\n          </span>\n        ))}\n      </span>\n    </span>\n  )\n}\n\nfunction UserAvatar({ className, user }: { className?: string; user: AppUser }) {\n  return (\n    <Avatar className={className}>\n      {user.avatar && <AvatarImage src={user.avatar} alt='' />}\n      <AvatarFallback>{getInitials(user.name)}</AvatarFallback>\n    </Avatar>\n  )\n}\n\nfunction UserSummary({ user }: { user: AppUser }) {\n  return (\n    <span className='grid flex-1 text-left text-sm leading-tight'>\n      <span className='truncate font-medium'>{user.name}</span>\n      <span className='truncate text-xs'>{user.email}</span>\n    </span>\n  )\n}\n\nfunction UserMenuItems({\n  links,\n  onNavigate,\n  onSignOut,\n  theme,\n  user,\n}: UserMenuProps & { onNavigate?: () => void }) {\n  return (\n    <>\n      <DropdownMenuGroup>\n        <DropdownMenuLabel className='flex items-center gap-2 font-normal'>\n          <UserAvatar user={user} />\n          <UserSummary user={user} />\n        </DropdownMenuLabel>\n      </DropdownMenuGroup>\n      <DropdownMenuSeparator />\n      {links.length > 0 && (\n        <>\n          <DropdownMenuGroup>\n            {links.map((link) => (\n              <DropdownMenuItem key={link.href} asChild>\n                <Link href={link.href} onClick={onNavigate}>\n                  {link.icon}\n                  {link.label}\n                </Link>\n              </DropdownMenuItem>\n            ))}\n          </DropdownMenuGroup>\n          <DropdownMenuSeparator />\n        </>\n      )}\n      {theme && (\n        <>\n          <DropdownMenuGroup>\n            <DropdownMenuItem\n              onClick={(event) =>\n                theme.onValueChange(pickedTheme(event.target, theme.value))\n              }\n            >\n              <IconPlaceholder\n                lucide='SunMoonIcon'\n                tabler='IconSunMoon'\n                hugeicons='ContrastIcon'\n                phosphor='CircleHalfIcon'\n                remixicon='RiContrast2Line'\n              />\n              Theme\n              <span className='sr-only'>: {themes[themeIndex(theme.value)].label}</span>\n              <ThemeSwitch value={theme.value} />\n            </DropdownMenuItem>\n          </DropdownMenuGroup>\n          <DropdownMenuSeparator />\n        </>\n      )}\n      <DropdownMenuItem onClick={onSignOut}>\n        <IconPlaceholder\n          lucide='LogOutIcon'\n          tabler='IconLogout'\n          hugeicons='Logout01Icon'\n          phosphor='SignOutIcon'\n          remixicon='RiLogoutBoxLine'\n        />\n        Sign out\n      </DropdownMenuItem>\n    </>\n  )\n}\n\nfunction SidebarUserMenu({\n  className,\n  ...props\n}: UserMenuProps & { className?: string }) {\n  const { isMobile } = useSidebar()\n  const closeMobile = useCloseMobileSidebar()\n  const railTooltip = useRailTooltip()\n  return (\n    <TooltipProvider>\n      <SidebarMenu>\n        <SidebarMenuItem>\n          <DropdownMenu modal={false}>\n            <DropdownMenuTrigger asChild>\n              <SidebarMenuButton\n                size='lg'\n                tooltip={railTooltip(props.user.name)}\n                className={cn('aria-expanded:bg-muted', className)}\n              >\n                <UserAvatar user={props.user} />\n                <UserSummary user={props.user} />\n                <IconPlaceholder\n                  lucide='ChevronsUpDownIcon'\n                  tabler='IconSelector'\n                  hugeicons='UnfoldMoreIcon'\n                  phosphor='CaretUpDownIcon'\n                  remixicon='RiArrowUpDownLine'\n                  className='ml-auto'\n                />\n              </SidebarMenuButton>\n            </DropdownMenuTrigger>\n            <DropdownMenuContent\n              className='min-w-56'\n              align='end'\n              side={isMobile ? 'bottom' : 'right'}\n            >\n              <UserMenuItems {...props} onNavigate={closeMobile} />\n            </DropdownMenuContent>\n          </DropdownMenu>\n        </SidebarMenuItem>\n      </SidebarMenu>\n    </TooltipProvider>\n  )\n}\n\nfunction UserMenu(props: UserMenuProps) {\n  return (\n    <DropdownMenu modal={false}>\n      <DropdownMenuTrigger asChild>\n        <Button\n          variant='ghost'\n          size='icon'\n          className='rounded-full'\n          aria-label={`${getInitials(props.user.name)}, account: ${props.user.name}`}\n        >\n          <UserAvatar user={props.user} />\n        </Button>\n      </DropdownMenuTrigger>\n      <DropdownMenuContent className='min-w-56' align='end'>\n        <UserMenuItems {...props} />\n      </DropdownMenuContent>\n    </DropdownMenu>\n  )\n}\n\ninterface AppHeaderProps {\n  children: ReactNode\n  className?: string\n}\n\nfunction AppHeader({ children, className }: AppHeaderProps) {\n  return (\n    <header\n      className={cn(\n        'bg-background sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b px-4 [html:has(&)]:scroll-pt-14',\n        className,\n      )}\n    >\n      {children}\n    </header>\n  )\n}\n\ninterface Crumb {\n  /** Leave out for the current page. */\n  href?: string\n  label: string\n}\n\nfunction AppBreadcrumbs({ className, items }: { className?: string; items: Crumb[] }) {\n  return (\n    <Breadcrumb className={cn('min-w-0', className)}>\n      <BreadcrumbList className='flex-nowrap'>\n        {items.map((item, index) => {\n          const last = index === items.length - 1\n          return (\n            <Fragment key={`${item.label}-${index}`}>\n              <BreadcrumbItem\n                className={cn(\n                  'min-w-0',\n                  last ? 'max-w-full shrink-0' : 'hidden md:inline-flex',\n                )}\n              >\n                {last ? (\n                  <BreadcrumbPage className='truncate'>{item.label}</BreadcrumbPage>\n                ) : item.href ? (\n                  <BreadcrumbLink className='truncate' title={item.label} asChild>\n                    <Link href={item.href}>{item.label}</Link>\n                  </BreadcrumbLink>\n                ) : (\n                  <span className='truncate' title={item.label}>\n                    {item.label}\n                  </span>\n                )}\n              </BreadcrumbItem>\n              {!last && <BreadcrumbSeparator className='hidden md:inline-flex' />}\n            </Fragment>\n          )\n        })}\n      </BreadcrumbList>\n    </Breadcrumb>\n  )\n}\n\ninterface SearchButtonProps {\n  className?: string\n  onOpen: () => void\n  /** @default 'Search' */\n  placeholder?: string\n  /** Below this width the field shrinks to its icon: `lg` for a bar that also holds tabs, `never` for a sidebar. @default 'sm' */\n  collapseBelow?: 'lg' | 'sm' | 'never'\n  /** Listens for ⌘K or Ctrl+K. Turn it off on a second Search button for the same search, so the key opens it once: the button still names the key to screen readers. @default true */\n  shortcut?: boolean\n  /** `secondary` fills the field instead of outlining it, for a bar on a tinted canvas where an outlined field stands out. @default 'outline' */\n  variant?: 'outline' | 'secondary'\n}\n\n/** Calls `onPress` on ⌘ or Ctrl with the letter `key`, unless the page already used the key. */\nfunction useShortcut(key: string | undefined, onPress: () => void) {\n  useEffect(() => {\n    if (!key) return\n    const letter = key.toLowerCase()\n    const onKeyDown = (event: KeyboardEvent) => {\n      // Chrome's autofill sends keydown events without a key.\n      if (event.defaultPrevented || event.key?.toLowerCase() !== letter) return\n      if (!(event.metaKey || event.ctrlKey)) return\n      event.preventDefault()\n      onPress()\n    }\n    window.addEventListener('keydown', onKeyDown, { capture: true })\n    return () => window.removeEventListener('keydown', onKeyDown, { capture: true })\n  }, [key, onPress])\n}\n\nconst searchCollapsed = {\n  lg: {\n    button: 'max-lg:aspect-square max-lg:px-0 lg:w-56 lg:justify-start',\n    key: 'max-lg:hidden',\n    label: 'max-lg:sr-only',\n  },\n  sm: {\n    button: 'max-sm:aspect-square max-sm:px-0 sm:w-56 sm:justify-start',\n    key: 'max-sm:hidden',\n    label: 'max-sm:sr-only',\n  },\n  never: { button: 'w-full justify-start', key: 'max-sm:hidden', label: '' },\n}\n\nfunction SearchButton({\n  className,\n  collapseBelow = 'sm',\n  onOpen,\n  placeholder = 'Search',\n  shortcut = true,\n  variant = 'outline',\n}: SearchButtonProps) {\n  useShortcut(shortcut ? 'k' : undefined, onOpen)\n  const collapsed = searchCollapsed[collapseBelow]\n\n  return (\n    <Button\n      variant={variant}\n      size='sm'\n      onClick={onOpen}\n      aria-keyshortcuts='Meta+K Control+K'\n      className={cn(collapsed.button, className)}\n    >\n      <IconPlaceholder\n        lucide='SearchIcon'\n        tabler='IconSearch'\n        hugeicons='SearchIcon'\n        phosphor='MagnifyingGlassIcon'\n        remixicon='RiSearchLine'\n      />\n      <span className={cn('text-muted-foreground font-normal', collapsed.label)}>\n        {placeholder}\n      </span>\n      <Kbd aria-hidden className={cn('ml-auto', collapsed.key)}>\n        ⌘K\n      </Kbd>\n    </Button>\n  )\n}\n\ninterface AppPanelProps {\n  /** The panel's content, such as a Copilot Panel, which fills its height. */\n  children: ReactNode\n  /** Names the panel for screen readers, such as `Ask AI`. */\n  label: string\n  onOpenChange: (open: boolean) => void\n  open: boolean\n}\n\nconst DOCKED_QUERY = '(min-width: 80rem)'\n\nfunction subscribeToDocked(onChange: () => void) {\n  const query = window.matchMedia(DOCKED_QUERY)\n  query.addEventListener('change', onChange)\n  return () => query.removeEventListener('change', onChange)\n}\n\n/** Whether the screen is wide enough for the page, the sidebar and a panel side by side. */\nfunction useDockedPanel() {\n  return useSyncExternalStore(\n    subscribeToDocked,\n    () => window.matchMedia(DOCKED_QUERY).matches,\n    () => false,\n  )\n}\n\n/** The panel's composer when it has one, else its first field or button. */\nfunction panelFocusTarget(root: HTMLElement | null) {\n  return (\n    root?.querySelector<HTMLElement>('textarea') ??\n    root?.querySelector<HTMLElement>('input, button:not([disabled])') ??\n    null\n  )\n}\n\n/** A panel beside the page on a wide screen, and a sheet over it on a smaller one. Put it after `SidebarInset`. */\nfunction AppPanel({ children, label, onOpenChange, open }: AppPanelProps) {\n  const docked = useDockedPanel()\n  const panelRef = useRef<HTMLElement>(null)\n  const sheetFocus = useRef<HTMLElement | null>(null)\n  const returnTo = useRef<HTMLElement | null>(null)\n  const focused = useRef(false)\n  const frameRef = useRef<HTMLDivElement>(null)\n  // A docked panel stays while it slides out, and the page narrows and widens with it.\n  const [present, setPresent] = useState(open)\n  const [shown, setShown] = useState(open)\n  if (open && !present) setPresent(true)\n  if (!open && shown) setShown(false)\n\n  useEffect(() => {\n    if (!open || shown) return\n    const frame = requestAnimationFrame(() => setShown(true))\n    return () => cancelAnimationFrame(frame)\n  }, [open, shown])\n\n  useEffect(() => {\n    const frame = frameRef.current\n    if (open || !present) return\n    let current = true\n    Promise.all(\n      (frame?.getAnimations() ?? []).map((animation) => animation.finished),\n    ).then(\n      () => {\n        if (current) setPresent(false)\n      },\n      () => {},\n    )\n    return () => {\n      current = false\n    }\n  }, [open, present])\n\n  useEffect(() => {\n    if (!docked || open === focused.current) return\n    focused.current = open\n    if (open) {\n      returnTo.current =\n        document.activeElement instanceof HTMLElement ? document.activeElement : null\n      panelFocusTarget(panelRef.current)?.focus()\n    } else if (returnTo.current?.isConnected) {\n      returnTo.current.focus()\n    }\n  }, [docked, open])\n\n  if (docked) {\n    if (!open && !present) return null\n    return (\n      <div\n        ref={frameRef}\n        data-state={shown ? 'open' : 'closed'}\n        inert={!open}\n        className='sticky top-0 h-svh w-96 shrink-0 overflow-clip transition-[width] duration-300 ease-[cubic-bezier(0.2,0,0,1)] data-[state=closed]:w-0 motion-reduce:transition-none'\n      >\n        <aside\n          ref={panelRef}\n          aria-label={label}\n          className='bg-background flex h-full w-96 flex-col border-l'\n        >\n          {children}\n        </aside>\n      </div>\n    )\n  }\n  return (\n    <Sheet open={open} onOpenChange={onOpenChange}>\n      <SheetContent\n        ref={(node) => {\n          sheetFocus.current = panelFocusTarget(node)\n        }}\n        aria-label={label}\n        showCloseButton={false}\n        className='w-full sm:max-w-md'\n        onOpenAutoFocus={(event) => {\n          event.preventDefault()\n          sheetFocus.current?.focus()\n        }}\n        onClick={(event) => {\n          const link =\n            event.target instanceof Element ? event.target.closest('a[href]') : null\n          if (link && isPlainClick(event) && link.getAttribute('target') !== '_blank') {\n            onOpenChange(false)\n          }\n        }}\n      >\n        {children}\n      </SheetContent>\n    </Sheet>\n  )\n}\n\ninterface PanelButtonProps {\n  className?: string\n  /** Leave out for a button with only its label. */\n  icon?: ReactNode\n  /** Such as `Ask AI`. */\n  label: string\n  onOpenChange: (open: boolean) => void\n  open: boolean\n  /** A letter that opens and closes the panel with ⌘ or Ctrl, such as `i`. */\n  shortcut?: string\n}\n\n/** The header button that opens and closes an `AppPanel`. */\nfunction PanelButton({\n  className,\n  icon,\n  label,\n  onOpenChange,\n  open,\n  shortcut,\n}: PanelButtonProps) {\n  useShortcut(shortcut, () => onOpenChange(!open))\n\n  const key = shortcut?.toUpperCase()\n  return (\n    <Button\n      variant='outline'\n      aria-expanded={open}\n      aria-keyshortcuts={key ? `Meta+${key} Control+${key}` : undefined}\n      onClick={() => onOpenChange(!open)}\n      className={cn(icon && 'max-lg:aspect-square max-lg:px-0', className)}\n    >\n      {icon}\n      <span className={cn(icon && 'max-lg:sr-only')}>{label}</span>\n      {key && (\n        <Kbd aria-hidden className='max-lg:hidden'>\n          ⌘{key}\n        </Kbd>\n      )}\n    </Button>\n  )\n}\n\ninterface NotificationsButtonProps {\n  className?: string\n  count: number\n  onClick: () => void\n}\n\nfunction NotificationsButton({ className, count, onClick }: NotificationsButtonProps) {\n  return (\n    <Button\n      variant='ghost'\n      size='icon'\n      onClick={onClick}\n      aria-label={count > 0 ? `Notifications, ${count} unread` : 'Notifications'}\n      className={cn('relative', className)}\n    >\n      <IconPlaceholder\n        lucide='BellIcon'\n        tabler='IconBell'\n        hugeicons='NotificationIcon'\n        phosphor='BellIcon'\n        remixicon='RiNotificationLine'\n      />\n      {count > 0 && (\n        <span className='bg-primary ring-background absolute top-1.5 right-1.5 size-2 rounded-full ring-2' />\n      )}\n    </Button>\n  )\n}\n\ninterface PlanUsageProps {\n  action?: { href: string; label: string }\n  limit: number\n  /** A line under the count, such as when the allowance resets. */\n  note?: ReactNode\n  /** What the allowance counts, such as `messages`. Leave it out to show only the share used. */\n  unit?: string\n  title: string\n  used: number\n}\n\nfunction PlanUsage({ action, limit, note, title, unit, used }: PlanUsageProps) {\n  const closeMobile = useCloseMobileSidebar()\n  return (\n    <div className='flex flex-col gap-2.5 border-t px-2 pt-3 pb-1 text-sm group-data-[collapsible=icon]:hidden'>\n      <div className='flex items-baseline justify-between gap-2'>\n        <span className='truncate font-medium'>{title}</span>\n        <PlanUsageShare className='shrink-0 text-xs' limit={limit} used={used} />\n      </div>\n      <UsageBar {...planUsageThresholds} limit={limit} size='sm' used={used} />\n      {(unit || note) && (\n        <div className='text-muted-foreground flex flex-col gap-0.5 text-xs text-pretty'>\n          {unit && (\n            <p>\n              <span className='text-foreground tabular-nums'>{formatNumber(used)}</span>{' '}\n              of <span className='tabular-nums'>{formatNumber(limit)}</span> {unit}\n            </p>\n          )}\n          {note && <p>{note}</p>}\n        </div>\n      )}\n      {action && (\n        <Link\n          href={action.href}\n          onClick={closeMobile}\n          className={buttonVariants({ size: 'sm' })}\n        >\n          {action.label}\n        </Link>\n      )}\n    </div>\n  )\n}\n\ninterface SidebarLayoutProps {\n  /** The bar over the page, after the button that opens the sidebar: a title and the page's actions. */\n  bar?: ReactNode\n  /** The sidebar's head, beside the button that closes it, such as the product's name. */\n  brand: ReactNode\n  children: ReactNode\n  /** Under the links, scrolling inside the sidebar, such as a list of chats. */\n  content?: ReactNode\n  /** The sidebar's foot, such as plan usage and the user menu. */\n  footer?: ReactNode\n  /** Links and actions at the top of the sidebar, which stay in view while the content scrolls. */\n  nav?: NavItem[]\n  pathname: string\n}\n\n/** A sidebar whose head, links and foot stay in view around content that scrolls, beside the page and its bar. */\nfunction SidebarLayout({\n  bar,\n  brand,\n  children,\n  content,\n  footer,\n  nav,\n  pathname,\n}: SidebarLayoutProps) {\n  return (\n    <SidebarProvider>\n      <Sidebar>\n        <SidebarLayoutHead brand={brand} nav={nav} pathname={pathname} />\n        <SidebarContent>{content}</SidebarContent>\n        {footer && <SidebarFooter>{footer}</SidebarFooter>}\n      </Sidebar>\n      <SidebarInset className='min-w-0'>\n        <SidebarLayoutBar>{bar}</SidebarLayoutBar>\n        {children}\n      </SidebarInset>\n    </SidebarProvider>\n  )\n}\n\nfunction SidebarLayoutHead({\n  brand,\n  nav,\n  pathname,\n}: Pick<SidebarLayoutProps, 'brand' | 'nav' | 'pathname'>) {\n  return (\n    <SidebarHeader>\n      <div className='flex h-10 items-center justify-between gap-2 ps-2'>\n        {brand}\n        <SidebarTrigger className='max-md:hidden' />\n      </div>\n      {nav && (\n        <TooltipProvider>\n          <SidebarMenu>\n            {nav.map((item) => (\n              <AppNavItem key={item.title} item={item} pathname={pathname} />\n            ))}\n          </SidebarMenu>\n        </TooltipProvider>\n      )}\n    </SidebarHeader>\n  )\n}\n\nfunction SidebarLayoutBar({ children }: { children: ReactNode }) {\n  const { state } = useSidebar()\n  return (\n    <AppHeader className='border-b-0'>\n      <SidebarTrigger className={cn('-ml-1', state === 'expanded' && 'md:hidden')} />\n      {children}\n    </AppHeader>\n  )\n}\n\ninterface TopNavProps {\n  className?: string\n  items: NavLink[]\n  pathname: string\n  /** `pill` fills the open link, for links that sit inside a bar. @default 'line' */\n  variant?: 'line' | 'pill'\n}\n\nfunction TopNav({ className, items, pathname, variant }: TopNavProps) {\n  return (\n    <nav aria-label='Main' className={cn('min-w-0 flex-1', className)}>\n      <TabLinks\n        items={items}\n        pathname={pathname}\n        isActive={(href) => isActiveHref(href, pathname)}\n        variant={variant}\n      />\n    </nav>\n  )\n}\n\ninterface MobileNavProps {\n  className?: string\n  items: NavLink[]\n  pathname: string\n  /** The sheet's heading, such as the app's brand. */\n  title: ReactNode\n}\n\n/** A menu button that opens the app's pages in a sheet, for a phone, where `TopNav` has no room. */\nfunction MobileNav({ className, items, pathname, title }: MobileNavProps) {\n  const [open, setOpen] = useState(false)\n  return (\n    <>\n      <Button\n        variant='secondary'\n        size='icon-sm'\n        aria-label='Open menu'\n        aria-expanded={open}\n        className={className}\n        onClick={() => setOpen(true)}\n      >\n        <IconPlaceholder\n          lucide='MenuIcon'\n          tabler='IconMenu2'\n          hugeicons='Menu01Icon'\n          phosphor='ListIcon'\n          remixicon='RiMenuLine'\n        />\n      </Button>\n      <Sheet open={open} onOpenChange={setOpen}>\n        <SheetContent side='left'>\n          <SheetHeader>\n            <SheetTitle className='flex items-center gap-2'>{title}</SheetTitle>\n          </SheetHeader>\n          <nav\n            aria-label='Main'\n            className='min-h-0 flex-1 overflow-y-auto px-2 pb-4 [scrollbar-width:thin]'\n          >\n            <MobileNavLinks\n              items={items}\n              onNavigate={() => setOpen(false)}\n              pathname={pathname}\n            />\n          </nav>\n        </SheetContent>\n      </Sheet>\n    </>\n  )\n}\n\nfunction MobileNavLinks({\n  items,\n  onNavigate,\n  pathname,\n}: Pick<MobileNavProps, 'items' | 'pathname'> & { onNavigate: () => void }) {\n  return (\n    <ul className='flex flex-col gap-0.5'>\n      {items.map((item) => {\n        const active = isActiveHref(item.href, pathname)\n        return (\n          <li key={item.href}>\n            <Link\n              href={item.href}\n              aria-current={active ? 'page' : undefined}\n              data-active={active || undefined}\n              onClick={(event) => {\n                if (isPlainClick(event)) onNavigate()\n              }}\n              className='text-muted-foreground hover:bg-foreground/5 hover:text-foreground data-active:bg-foreground/10 data-active:text-foreground focus-visible:ring-ring/50 flex h-11 items-center gap-4 rounded-md px-4 text-sm font-medium outline-none focus-visible:ring-3 [&_svg]:size-4 [&_svg]:shrink-0'\n            >\n              {item.icon}\n              <span className='min-w-0 flex-1 truncate'>{item.title}</span>\n              {item.badge !== undefined && renderTag(item.badge)}\n            </Link>\n          </li>\n        )\n      })}\n    </ul>\n  )\n}\n\nexport {\n  AppBrand,\n  AppPanel,\n  AppBreadcrumbs,\n  AppHeader,\n  AppNav,\n  BrandMark,\n  getInitials,\n  isActiveHref,\n  MobileNav,\n  NotificationsButton,\n  PanelButton,\n  PlanUsage,\n  SearchButton,\n  SidebarLayout,\n  SidebarUserMenu,\n  TopNav,\n  useDockedPanel,\n  UserMenu,\n  useShortcut,\n  WorkspaceSwitcher,\n}\n\nexport type {\n  AppBrandProps,\n  AppTheme,\n  AppPanelProps,\n  AppHeaderProps,\n  AppNavProps,\n  AppUser,\n  Crumb,\n  MobileNavProps,\n  NavItem,\n  NavLink,\n  NavSection,\n  NotificationsButtonProps,\n  PanelButtonProps,\n  PlanUsageProps,\n  SearchButtonProps,\n  SidebarLayoutProps,\n  ThemeChoice,\n  TopNavProps,\n  UserMenuLink,\n  UserMenuProps,\n  Workspace,\n  WorkspaceSwitcherProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/app-shell.tsx"
    },
    {
      "path": "registry/hooks/use-mobile.ts",
      "content": "import * as React from 'react'\n\nconst MOBILE_BREAKPOINT = 768\nconst QUERY = `(max-width: ${MOBILE_BREAKPOINT - 1}px)`\n\nfunction subscribe(onChange: () => void) {\n  const mql = window.matchMedia(QUERY)\n  mql.addEventListener('change', onChange)\n  return () => mql.removeEventListener('change', onChange)\n}\n\nexport function useIsMobile() {\n  return React.useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(QUERY).matches,\n    () => false,\n  )\n}\n",
      "type": "registry:hook",
      "target": "@hooks/use-mobile.ts"
    }
  ],
  "type": "registry:component"
}
