{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "retro-app-switcher",
  "title": "RetroAppSwitcher",
  "description": "The Mac OS 9 Application menu for the right end of the menu bar: frontmost app icon and name, Hide, Hide Others, Show All, and a checkmarked list of running apps.",
  "registryDependencies": [
    "https://nostalgia-ui.com/r/nostalgia-theme.json",
    "https://nostalgia-ui.com/r/retro-dropdown-menu.json"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/retro-app-switcher.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport {\n  RetroDropdownMenu,\n  RetroDropdownMenuContent,\n  RetroDropdownMenuItem,\n  RetroDropdownMenuSeparator,\n  RetroDropdownMenuTrigger,\n} from \"@/registry/new-york/ui/retro-dropdown-menu\"\n\n/* ------------------------------------------------------------------ */\n/*  Types                                                              */\n/* ------------------------------------------------------------------ */\n\nexport interface AppSwitcherApp {\n  id: string\n  name: string\n  /** 16x16 icon. Defaults to a generic application icon. */\n  icon?: React.ReactNode\n  /** Hidden apps are listed with a dimmed icon. */\n  hidden?: boolean\n}\n\nexport interface RetroAppSwitcherProps\n  extends Omit<\n    React.ButtonHTMLAttributes<HTMLButtonElement>,\n    \"defaultValue\" | \"children\"\n  > {\n  /** Running applications, in menu order. */\n  apps: AppSwitcherApp[]\n  /** Controlled frontmost app id. */\n  activeApp?: string\n  /** Uncontrolled initial frontmost app id. Defaults to the first app. */\n  defaultActiveApp?: string\n  /** Fired when the user picks an app from the list. */\n  onActiveAppChange?: (id: string) => void\n  /** \"Hide <App>\" — receives the frontmost app id. */\n  onHide?: (id: string) => void\n  /** \"Hide Others\" — receives the frontmost app id. */\n  onHideOthers?: (id: string) => void\n  /** \"Show All\". */\n  onShowAll?: () => void\n  /** Show the app name next to the icon in the trigger. Defaults to true. */\n  showLabel?: boolean\n  /** Controlled menu open state. */\n  open?: boolean\n  onOpenChange?: (open: boolean) => void\n}\n\n/* ------------------------------------------------------------------ */\n/*  Default application icon (16x16)                                   */\n/* ------------------------------------------------------------------ */\n\nconst RetroAppSwitcherDefaultIcon = React.forwardRef<\n  SVGSVGElement,\n  React.SVGProps<SVGSVGElement>\n>(function RetroAppSwitcherDefaultIcon({ className, ...props }, ref) {\n  return (\n    <svg\n      ref={ref}\n      width=\"16\"\n      height=\"16\"\n      viewBox=\"0 0 16 16\"\n      aria-hidden=\"true\"\n      className={cn(\"shrink-0\", className)}\n      {...props}\n    >\n      {/* Classic \"generic application\" diamond with hand-and-pen feel */}\n      <path d=\"M8 1.5L14.5 8L8 14.5L1.5 8Z\" fill=\"#ccccff\" stroke=\"#262626\" />\n      <path d=\"M8 3L13 8\" stroke=\"#ffffff\" />\n      <path d=\"M8 13L13 8\" stroke=\"#6666cc\" />\n      <path d=\"M6 9.5L9.5 6M7 10.5L10.5 7\" stroke=\"#333399\" />\n    </svg>\n  )\n})\nRetroAppSwitcherDefaultIcon.displayName = \"RetroAppSwitcherDefaultIcon\"\n\n/* ------------------------------------------------------------------ */\n/*  RetroAppSwitcher                                                   */\n/* ------------------------------------------------------------------ */\n\n/**\n * The Application menu at the right end of the Mac OS 9 menu bar.\n * Place it inside RetroDesktopMenuBar / RetroMenuBar with `className=\"ml-auto\"`.\n */\nconst RetroAppSwitcher = React.forwardRef<HTMLButtonElement, RetroAppSwitcherProps>(\n  function RetroAppSwitcher(\n    {\n      apps,\n      activeApp: activeProp,\n      defaultActiveApp,\n      onActiveAppChange,\n      onHide,\n      onHideOthers,\n      onShowAll,\n      showLabel = true,\n      open,\n      onOpenChange,\n      className,\n      ...props\n    },\n    ref\n  ) {\n    const [internalActive, setInternalActive] = React.useState(\n      defaultActiveApp ?? apps[0]?.id\n    )\n    const activeId = activeProp ?? internalActive\n    const active = apps.find((a) => a.id === activeId) ?? apps[0]\n\n    const setActive = (id: string) => {\n      if (activeProp === undefined) setInternalActive(id)\n      onActiveAppChange?.(id)\n    }\n\n    const othersVisible = apps.some((a) => a.id !== active?.id && !a.hidden)\n    const anyHidden = apps.some((a) => a.hidden)\n\n    const iconFor = (app: AppSwitcherApp) =>\n      app.icon ?? <RetroAppSwitcherDefaultIcon />\n\n    return (\n      <RetroDropdownMenu open={open} onOpenChange={onOpenChange} modal={false}>\n        <RetroDropdownMenuTrigger\n          render={\n            <button\n              ref={ref}\n              type=\"button\"\n              aria-label={`Application menu: ${active?.name ?? \"none\"}`}\n              className={cn(\n                \"relative flex h-[19px] shrink-0 cursor-default select-none items-center gap-[4px] px-[8px] pt-[1px]\",\n                /* Divider separating the app menu from the rest of the bar */\n                \"border-l border-os9-gray-700 shadow-[inset_1px_0_0_var(--os9-white)]\",\n                \"font-[family-name:var(--os9-font-heading)] text-[12px] tracking-[0.42px] leading-[0.98]\",\n                \"text-os9-black outline-none whitespace-nowrap\",\n                \"data-open:bg-os9-azul data-open:text-os9-white data-open:shadow-none\",\n                \"focus-visible:bg-os9-azul focus-visible:text-os9-white\",\n                className\n              )}\n              {...props}\n            />\n          }\n        >\n          {active && (\n            <span className=\"flex size-[16px] items-center justify-center\" aria-hidden=\"true\">\n              {iconFor(active)}\n            </span>\n          )}\n          {showLabel && active && <span>{active.name}</span>}\n        </RetroDropdownMenuTrigger>\n        <RetroDropdownMenuContent align=\"end\" sideOffset={0} className=\"min-w-[180px]\">\n          <RetroDropdownMenuItem\n            disabled={!active}\n            onSelect={() => active && onHide?.(active.id)}\n          >\n            Hide {active?.name}\n          </RetroDropdownMenuItem>\n          <RetroDropdownMenuItem\n            disabled={!othersVisible}\n            onSelect={() => active && onHideOthers?.(active.id)}\n          >\n            Hide Others\n          </RetroDropdownMenuItem>\n          <RetroDropdownMenuItem disabled={!anyHidden} onSelect={() => onShowAll?.()}>\n            Show All\n          </RetroDropdownMenuItem>\n          <RetroDropdownMenuSeparator />\n          {apps.map((app) => {\n            const isActive = app.id === active?.id\n            return (\n              <RetroDropdownMenuItem\n                key={app.id}\n                role=\"menuitemradio\"\n                aria-checked={isActive}\n                onSelect={() => setActive(app.id)}\n                className=\"relative gap-[6px] pl-[18px]\"\n              >\n                {isActive && (\n                  <svg\n                    width=\"9\"\n                    height=\"9\"\n                    viewBox=\"0 0 16 16\"\n                    aria-hidden=\"true\"\n                    className=\"absolute left-[5px]\"\n                  >\n                    <path\n                      d=\"M3 8.5L6.5 12L13 4\"\n                      fill=\"none\"\n                      stroke=\"currentColor\"\n                      strokeWidth=\"2.5\"\n                      strokeLinecap=\"square\"\n                    />\n                  </svg>\n                )}\n                <span\n                  aria-hidden=\"true\"\n                  className={cn(\n                    \"flex size-[16px] shrink-0 items-center justify-center\",\n                    app.hidden && \"opacity-40\"\n                  )}\n                >\n                  {iconFor(app)}\n                </span>\n                <span>{app.name}</span>\n              </RetroDropdownMenuItem>\n            )\n          })}\n        </RetroDropdownMenuContent>\n      </RetroDropdownMenu>\n    )\n  }\n)\nRetroAppSwitcher.displayName = \"RetroAppSwitcher\"\n\nexport { RetroAppSwitcher, RetroAppSwitcherDefaultIcon }\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}