import { ILogItemsByUser } from "@ax/types";
import { SET_ACTIVITY_LOG, SET_LIST_MODE } from "./constants";
import { ILogItemsByDay } from "src/types/logs";

export interface IActivityLogState {
	activityLog: ILogItemsByDay | ILogItemsByUser;
	listMode: string;
}

export const initialState: IActivityLogState = {
	activityLog: { totalItems: 0, items: [] },
	listMode: "default",
};

export function reducer(state = initialState, action: any): IActivityLogState {
	switch (action.type) {
		case SET_ACTIVITY_LOG:
		case SET_LIST_MODE:
			return { ...state, ...action.payload };
		default:
			return state;
	}
}

export { initialState as activityLogInitialState, reducer as activityLogReducer };
