"use client"; import { useEffect, useState } from "react"; import { Moon, Monitor, Sun } from "lucide-react"; import { useTheme } from "@/providers/theme-provider"; import { useI18n } from "@/i18n/i18n-context"; import { cn } from "@/lib/utils"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@/components/ui/tooltip"; type ThemeMode = "light" | "system" | "dark"; const MODES: ThemeMode[] = ["light", "system", "dark"]; const LABEL_KEYS: Record< ThemeMode, "theme.light" | "theme.system" | "theme.dark" > = { light: "theme.light", system: "theme.system", dark: "theme.dark", }; interface ThemeToggleProps { collapsed?: boolean; } export function ThemeToggle({ collapsed }: ThemeToggleProps) { const { theme, setTheme, resolvedTheme } = useTheme(); const { t } = useI18n(); const [mounted, setMounted] = useState(false); useEffect(() => setMounted(true), []); if (!mounted) { return
; } const current: ThemeMode = (theme as ThemeMode) ?? "system"; const nextIndex = (MODES.indexOf(current) + 1) % MODES.length; const nextMode = MODES[nextIndex]; const displayMode: "light" | "dark" = current === "system" ? resolvedTheme === "dark" ? "dark" : "light" : current; return ( {t("theme.current", { current: t(LABEL_KEYS[current]), next: t(LABEL_KEYS[nextMode]), })} ); }