import { create } from 'zustand' export type Theme = 'dark' | 'light' interface ThemeState { theme: Theme setTheme: (theme: Theme) => void toggleTheme: () => void } function getInitialTheme(): Theme { const stored = localStorage.getItem('yace_theme') if (stored === 'light' || stored === 'dark') return stored return 'dark' } function applyTheme(theme: Theme) { document.documentElement.setAttribute('data-theme', theme) } const initial = getInitialTheme() applyTheme(initial) export const useThemeStore = create((set) => ({ theme: initial, setTheme: (theme: Theme) => { applyTheme(theme) localStorage.setItem('yace_theme', theme) set({ theme }) }, toggleTheme: () => { set((state) => { const next = state.theme === 'dark' ? 'light' : 'dark' applyTheme(next) localStorage.setItem('yace_theme', next) return { theme: next } }) }, }))