import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { TimeFormats } from "utility";

export interface IPreferredTimeFormatState {
    isLoading: boolean;
    error: null | string;
    timeFormat: TimeFormats;
}

export const initialPreferredTimeFormatState: IPreferredTimeFormatState = {
    isLoading: false,
    error: null,
    timeFormat: TimeFormats.Utc
}

export const preferredTimeFormatSlice = createSlice({
    name: 'preferredTimeFormat',
    initialState: initialPreferredTimeFormatState,
    reducers: {
        setPreferredTimeFormat: (state: IPreferredTimeFormatState, action: PayloadAction<TimeFormats>) => {
            state.timeFormat = action.payload;
        }
    }
})

export const { setPreferredTimeFormat } = preferredTimeFormatSlice.actions;
export default preferredTimeFormatSlice.reducer;