import { createSlice, PayloadAction } from '@reduxjs/toolkit';

interface SettingsState {
  sidebarCollapsed: boolean;
  theme: 'light' | 'dark';
  language: 'zh-CN' | 'en-US';
}

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

const settingsSlice = createSlice({
  name: 'settings',
  initialState,
  reducers: {
    toggleSidebar: (state) => {
      state.sidebarCollapsed = !state.sidebarCollapsed;
    },
    setSidebarCollapsed: (state, action: PayloadAction<boolean>) => {
      state.sidebarCollapsed = action.payload;
    },
    setTheme: (state, action: PayloadAction<'light' | 'dark'>) => {
      state.theme = action.payload;
    },
    setLanguage: (state, action: PayloadAction<'zh-CN' | 'en-US'>) => {
      state.language = action.payload;
    },
  },
});

export const { toggleSidebar, setSidebarCollapsed, setTheme, setLanguage } = settingsSlice.actions;
export default settingsSlice.reducer;
