/**
 * Settings Store - Zustand
 * ========================
 */

import { create } from 'zustand';
import { persist } from 'zustand/middleware';

export type ThemeMode = 'light' | 'dark' | 'system';

interface SettingsState {
  theme: ThemeMode;
  language: string;
  isDark: boolean;
}

interface SettingsActions {
  setTheme: (_theme: ThemeMode) => void;
  setLanguage: (_language: string) => void;
}
 

type SettingsStore = SettingsState & SettingsActions;

const initialState: SettingsState = {
  theme: 'light',
  language: 'zh-CN',
  isDark: false,
};

export const useSettingsStore = create<SettingsStore>()(
  persist(
    set => ({
      ...initialState,

      setTheme: theme =>
        set({
          theme,
          isDark:
            theme === 'dark' ||
            (theme === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches),
        }),
      setLanguage: language => set({ language }),
    }),
    {
      name: 'ai-video-settings',
    }
  )
);
