{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "theme-switcher",
  "title": "Theme Switcher",
  "author": "jyotirmoydas <jyotirmoydas12345@gmail.com>",
  "description": "A theme switcher component for Next.js apps with next-themes and Tailwind CSS, supporting system, light, and dark modes.",
  "dependencies": ["cn", "next-themes", "lucide-react", "motion"],
  "registryDependencies": [
    "https://jyotimoydas.in/r/use-sound.json",
    "https://jyotimoydas.in/r/use-theme-transition.json"
  ],
  "files": [
    {
      "path": "src/registry/theme-switcher/theme-switcher.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"cn\";\nimport { MonitorIcon, MoonIcon, MoonStarIcon, SunIcon } from \"lucide-react\";\nimport { motion } from \"motion/react\";\nimport { useTheme } from \"next-themes\";\nimport type { JSX } from \"react\";\nimport { useCallback, useRef, useSyncExternalStore } from \"react\";\n\nimport { useSound } from \"@/hooks/use-sound\";\nimport { useThemeTransition } from \"@/hooks/use-theme-transition\";\n\n// =============================================================================\n// Types\n// =============================================================================\n\ninterface ThemeSwitcherProps {\n  /**\n   * The style variant of the switcher.\n   * - `\"tri-toggle\"`: 3 options (System, Light, Dark) - default\n   * - `\"toggle\"`: 2 options (Light/Dark toggle)\n   */\n  variant?: \"toggle\" | \"tri-toggle\";\n  /**\n   * Enable click sound on theme change for added immersion.\n   */\n  sound?: boolean;\n}\n\n// =============================================================================\n// Sub-components\n// =============================================================================\n\nfunction ThemeOptionButton({\n  icon,\n  value,\n  isActive,\n  onClick,\n}: {\n  icon: JSX.Element;\n  value: string;\n  isActive?: boolean;\n  onClick: (value: string, button: HTMLButtonElement) => void;\n}) {\n  return (\n    <button\n      className={cn(\n        \"relative flex size-8 cursor-default items-center justify-center rounded-full transition-[color] [&_svg]:size-4\",\n        isActive\n          ? \"text-zinc-950 dark:text-zinc-50\"\n          : \"text-zinc-400 hover:text-zinc-950 dark:text-zinc-500 dark:hover:text-zinc-50\"\n      )}\n      role=\"radio\"\n      aria-checked={isActive}\n      aria-label={`Switch to ${value} theme`}\n      onClick={(e) => onClick(value, e.currentTarget)}\n    >\n      {icon}\n      {isActive && (\n        <motion.div\n          layoutId=\"theme-option\"\n          transition={{ type: \"spring\", bounce: 0.3, duration: 0.6 }}\n          className=\"absolute inset-0 rounded-full border border-zinc-200 dark:border-zinc-700\"\n        />\n      )}\n    </button>\n  );\n}\n\n// =============================================================================\n// Constants\n// =============================================================================\n\nconst TRI_TOGGLE_OPTIONS = [\n  { icon: <MonitorIcon />, value: \"system\" },\n  { icon: <SunIcon />, value: \"light\" },\n  { icon: <MoonStarIcon />, value: \"dark\" },\n];\n\n// =============================================================================\n// Main Component\n// =============================================================================\n\nfunction ThemeSwitcher({\n  variant = \"tri-toggle\",\n  sound = false,\n}: ThemeSwitcherProps) {\n  const { theme, resolvedTheme, setTheme } = useTheme();\n  const buttonRef = useRef<HTMLButtonElement>(null);\n  const triggerTransition = useThemeTransition(buttonRef);\n  const playClick = useSound(\"/audio/ui-sounds/click.wav\");\n\n  const isMounted = useSyncExternalStore(\n    () => () => {},\n    () => true,\n    () => false\n  );\n\n  const handleThemeChange = useCallback(\n    (value: string, button: HTMLButtonElement) => {\n      (buttonRef as React.MutableRefObject<HTMLButtonElement | null>).current =\n        button;\n\n      if (sound) playClick(0.5);\n\n      triggerTransition(() => {\n        setTheme(value);\n      });\n    },\n    [sound, playClick, triggerTransition, setTheme]\n  );\n\n  const handleToggle = useCallback(\n    (button: HTMLButtonElement) => {\n      (buttonRef as React.MutableRefObject<HTMLButtonElement | null>).current =\n        button;\n\n      if (sound) playClick(0.5);\n\n      triggerTransition(() => {\n        setTheme(resolvedTheme === \"dark\" ? \"light\" : \"dark\");\n      });\n    },\n    [sound, playClick, triggerTransition, setTheme, resolvedTheme]\n  );\n\n  if (!isMounted) {\n    return (\n      <div\n        className={cn(\"flex h-8\", variant === \"tri-toggle\" ? \"w-24\" : \"w-8\")}\n      />\n    );\n  }\n\n  // Toggle variant (simple light/dark)\n  if (variant === \"toggle\") {\n    const isDark = resolvedTheme === \"dark\";\n    return (\n      <motion.button\n        ref={buttonRef}\n        initial={{ opacity: 0 }}\n        animate={{ opacity: 1 }}\n        transition={{ duration: 0.3 }}\n        className=\"inline-flex size-8 cursor-default items-center justify-center rounded-full bg-white text-zinc-950 ring-1 ring-zinc-200 transition-colors ring-inset dark:bg-zinc-950 dark:text-zinc-50 dark:ring-zinc-700 [&_svg]:size-4\"\n        onClick={(e) => handleToggle(e.currentTarget)}\n        aria-label={`Switch to ${isDark ? \"light\" : \"dark\"} theme`}\n      >\n        {isDark ? <SunIcon /> : <MoonIcon />}\n      </motion.button>\n    );\n  }\n\n  // Tri-toggle variant (system/light/dark)\n  return (\n    <motion.div\n      key={String(isMounted)}\n      initial={{ opacity: 0 }}\n      animate={{ opacity: 1 }}\n      transition={{ duration: 0.3 }}\n      className=\"inline-flex items-center overflow-hidden rounded-full bg-white ring-1 ring-zinc-200 ring-inset dark:bg-zinc-950 dark:ring-zinc-700\"\n      role=\"radiogroup\"\n    >\n      {TRI_TOGGLE_OPTIONS.map((option) => (\n        <ThemeOptionButton\n          key={option.value}\n          icon={option.icon}\n          value={option.value}\n          isActive={theme === option.value}\n          onClick={handleThemeChange}\n        />\n      ))}\n    </motion.div>\n  );\n}\n\nexport type { ThemeSwitcherProps };\nexport { ThemeSwitcher };\n",
      "type": "registry:component"
    }
  ],
  "docs": "https://jyotimoydas.in/components/theme-switcher-component",
  "type": "registry:component"
}
