'use client'; import { useEffect, useState } from 'react'; type Theme = 'dark' | 'light' | 'custom'; const ThemeSwitcher = ({ className }: { className?: string }) => { const [mounted, setMounted] = useState(false); const [theme, setTheme] = useState('dark'); const [bg, setBg] = useState(''); const [accent, setAccent] = useState(''); useEffect(() => { setMounted(true); const t = (localStorage.getItem('appTheme') as Theme) || 'dark'; const b = localStorage.getItem('userBg') || '#0f0f0f'; const a = localStorage.getItem('userAccent') || '#2563eb'; setTheme(t); setBg(b); setAccent(a); }, []); const apply = (next: Theme, nextBg = bg, nextAccent = accent) => { (window as any).__setAppTheme?.(next, nextBg, nextAccent); setTheme(next); if (next === 'light' || next === 'dark') { // Refresh local color inputs from storage so UI shows current defaults const b = localStorage.getItem('userBg') || '#0f0f0f'; const a = localStorage.getItem('userAccent') || '#2563eb'; setBg(b); setAccent(a); } }; if (!mounted) return null; return (
{theme === 'custom' && (
{ const v = e.target.value; setBg(v); apply('custom', v, accent); }} /> { const v = e.target.value; setAccent(v); apply('custom', bg, v); }} />
)}
); }; export default ThemeSwitcher;