"use client"; import { useState } from "react"; import { useHydrated } from "@/components/ui/use-hydrated"; import { THEMES, themeAttr, themeCookie, type Theme } from "@/lib/theme"; // Auto / Light / Dark, at the foot of the rail. A choice writes the cookie the // root layout reads (lib/theme.ts) and stamps at once, so this page // changes now and every later page is served in it -- no reload, no flash. export default function ThemeControl({ initial }: { initial: Theme }) { const hydrated = useHydrated(); const [theme, setTheme] = useState(initial); const choose = (t: Theme) => { document.cookie = themeCookie(t); const attr = themeAttr(t); if (attr) document.documentElement.dataset.theme = attr; else delete document.documentElement.dataset.theme; setTheme(t); }; return (
{THEMES.map((t, i) => ( ))}
); }