import { useState, useEffect } from "react"; import { Moon, Sun } from "lucide-react"; export function useTheme() { const [theme, setTheme] = useState<"light" | "dark">("dark"); const [mounted, setMounted] = useState(false); useEffect(() => { setMounted(true); if (typeof window !== "undefined") { const stored = localStorage.getItem("aethex_theme"); if (stored === "light" || stored === "dark") { setTheme(stored); } } }, []); useEffect(() => { if (!mounted) return; const root = document.documentElement; if (theme === "light") { root.classList.remove("dark"); root.classList.add("light"); } else { root.classList.remove("light"); root.classList.add("dark"); } if (typeof window !== "undefined") { localStorage.setItem("aethex_theme", theme); } }, [theme, mounted]); const toggleTheme = () => { setTheme((prev) => (prev === "dark" ? "light" : "dark")); }; return { theme, setTheme, toggleTheme }; } export function ThemeToggle() { const { theme, toggleTheme } = useTheme(); return ( ); }