"use client"; import { useTheme } from "next-themes"; import { flushSync } from "react-dom"; export function ThemeToggle() { const { resolvedTheme, setTheme } = useTheme(); const toggle = () => { const next = resolvedTheme === "dark" ? "light" : "dark"; const apply = () => { setTheme(next); const meta = document.querySelector('meta[name="theme-color"]'); if (meta) meta.setAttribute("content", next === "dark" ? "#0a0a0a" : "#fafafa"); }; if ( !document.startViewTransition || window.matchMedia("(prefers-reduced-motion: reduce)").matches ) { apply(); return; } document.startViewTransition(() => { flushSync(apply); }); }; return ( ); }