import type { PayloadAction } from "@reduxjs/toolkit"

import { createSlice } from "@reduxjs/toolkit"

import type { AppState, ThemePreference } from "./types"

const initialState: AppState = {
	themePreference: "system",
}

const appStateSlice = createSlice({
	name: "appState",
	initialState,
	reducers: {
		resetAppState() {
			return initialState
		},
		setThemePreference(state, action: PayloadAction<ThemePreference>) {
			state.themePreference = action.payload
		},
	},
})

export const { resetAppState, setThemePreference } = appStateSlice.actions
export const appStateReducer = appStateSlice.reducer
