import ScanActionTypes from "./scan.types";

const INITIAL_STATE = {
  loading: false,
  lastScanned: null,
  estimates: [],
};

const applicationReducer = (state = INITIAL_STATE, action) => {
  switch (action.type) {
    case ScanActionTypes.SET_LIST_OF_ESTIMATES:
      return {
        ...state,
        loading: false,
        estimates: action.payload,
        lastScanned: new Date(),
      };
    case ScanActionTypes.SCAN_START:
      return { ...state, loading: true };
    case ScanActionTypes.CLEAR_LIST_OF_ESTIMATES:
      return { ...state, estimates: [], lastScanned: null };
    default:
      return state;
  }
};

export default applicationReducer;
