import type { NPEDACTION, NPEDSTATE } from "../../types/types";

export const initialState = {
  sessionStarted: false,
  sessionList: [],
  sessionPaused: false,
  savedSightings: [],
  npedUser: null,
};

export function reducer(state: NPEDSTATE, action: NPEDACTION) {
  switch (action.type) {
    case "SESSIONSTART":
      return {
        ...state,
        sessionStarted: action.payload,
      };
    case "LOGIN":
      return {
        ...state,
        npedUser: action.payload,
      };
    case "LOGOUT":
      return {
        ...state,
        npedUser: action.payload,
      };
    case "SESSIONPAUSE":
      return {
        ...state,
        sessionPaused: action.payload,
      };
    case "ADD":
      return {
        ...state,
        sessionList: [...state.sessionList, action.payload],
      };
    case "UPDATE":
      return {
        ...state,
        sessionList: action.payload,
      };
    default:
      return { ...state };
  }
}
