/* eslint-disable no-param-reassign */
import produce from 'immer';
import { ReduxActionTypes } from '../../constants/actionTypes';

export const initialState = {
  data: {},
  isLoading: false,
  error: false,
};

const clock = (state = initialState, action) => (
  produce(state, (draft) => {
    switch (action.type) {
      case ReduxActionTypes.FETCH_DATA:
        draft.isLoading = true;
        break;
      case ReduxActionTypes.FETCH_DATA_SUC:
        draft.isLoading = false;
        break;
      case ReduxActionTypes.FETCH_DATA_FAL:
        draft.isLoading = false;
        break;
      default:
        break;
    }
  })
);

export default clock;
