import { create } from 'zustand';

type ThemeMode = 'dark' | 'light';

interface ThemeState {
  theme: ThemeMode;
  toggleTheme: () => void;
  setTheme: (mode: ThemeMode) => void;
}

export const useThemeStore = create<ThemeState>((set, get) => ({
  theme: (localStorage.getItem('wing-theme') as ThemeMode) || 'dark',

  toggleTheme: () => {
    const next = get().theme === 'dark' ? 'light' : 'dark';
    localStorage.setItem('wing-theme', next);
    document.documentElement.setAttribute('data-theme', next);
    set({ theme: next });
  },

  setTheme: (mode) => {
    localStorage.setItem('wing-theme', mode);
    document.documentElement.setAttribute('data-theme', mode);
    set({ theme: mode });
  },
}));
