import { useState } from 'react'; import { Check } from 'lucide-react'; import { toast } from 'sonner'; import { Card } from '@/components/ui/card'; import { Label } from '@/components/ui/label'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { THEMES, setTheme, useTheme, type ThemeId, type ThemeMode } from '@/lib/theme'; import { cn } from '@/lib/utils'; // v1.9: lifted out of pages/Settings.tsx so the SettingsPane Theme tab and // the standalone /settings route render the same picker. Theme is global — // not per-project, not per-session — so no contextual props are needed. const MODES: { value: ThemeMode; label: string; hint: string }[] = [ { value: 'dark', label: 'Dark', hint: 'Use the dark variant.' }, { value: 'light', label: 'Light', hint: 'Use the light variant.' }, { value: 'system', label: 'System', hint: 'Follow OS preference.' }, ]; export function ThemePicker() { const { id: currentId, mode: currentMode } = useTheme(); // Track the most recent in-flight pick so the picker can show a subtle // "applying…" state on the targeted card while the PATCH is in flight. const [pending, setPending] = useState< { kind: 'theme'; id: ThemeId } | { kind: 'mode'; mode: ThemeMode } | null >(null); async function pickTheme(id: ThemeId) { if (id === currentId || pending) return; setPending({ kind: 'theme', id }); try { await setTheme(id, currentMode); } catch (err) { toast.error(err instanceof Error ? err.message : 'failed to apply theme'); } finally { setPending(null); } } async function pickMode(mode: ThemeMode) { if (mode === currentMode || pending) return; setPending({ kind: 'mode', mode }); try { await setTheme(currentId, mode); } catch (err) { toast.error(err instanceof Error ? err.message : 'failed to apply mode'); } finally { setPending(null); } } return (