import { SET_LOGBOOK_CONTEXT } from '../constants/actionTypes';

// initialize the logbook redux state
const initialState = {
  context: {
    name: null,
    isReleased: null,
  },
};

/**
 *  The logbook reducer. THe reducer takes the current state and the action and returns the new state
 */
const logbookReducer = (state = initialState, action) => {
  switch (action.type) {
    case SET_LOGBOOK_CONTEXT: {
      state = {
        ...state,
        context: {
          name: action.context.name,
          isReleased: action.context.isReleased,
        },
      };
      break;
    }

    default:
      break; // leave the state unchanged when the action should have no impact on current logbook store state
  }

  return state;
};

export default logbookReducer;
