import { UPDATE_REPORTS /* , GET_REPORT_SUCCESS */ } from '../constants/actionTypes';
const initialState = {
  data: []
};
export function reports() {
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
  let action = arguments.length > 1 ? arguments[1] : undefined;
  /* if (action.type === GET_REPORT_SUCCESS) {
    const id = action.data.id;
    return {
      ...state,
      data: state.data.map(d => (d.id === id ? action.data : d))
    };
  } else */
  if (action.type !== UPDATE_REPORTS) return state;
  const request = action.request;
  switch (request.type) {
    case 'list':
      return {
        ...state,
        data: request.data
      };
    case 'add':
      return {
        ...state,
        data: [...state.data, request.data]
      };
    case 'remove':
      return {
        ...state,
        data: state.data.filter(d => d.id !== request.id)
      };
    default:
      return state;
  }
}