import { DMap } from "react-native-digitcamera/src/Screens/SilentUploadV2/DMap";

const intialState = {
  dProgressMap: {},
};

const clearState = {
  dProgressMap: {},
};

export default (state = intialState, action) => {
  switch (action.type) {
    case "ADD_UPLOAD_PROGRESS_DATA": {
      const {
        activityId,
        imageName,
        progress,
        uploadSpeed,
        secondsRemaining,
      } = action.payload;
      console.log(`[UPLOADPROGRESS] ${activityId}_${imageName}`);
      const key = `${activityId}_${imageName}`;
      const newMap = { ...state.dProgressMap };
      newMap[key] = {
        progress: progress,
        uploadSpeed: uploadSpeed,
        secondsRemaining: secondsRemaining,
      };
      console.log(
        `[UPLOADPROGRESS] added progress of ${key} progress:${newMap[key]}`
      );
      return { ...state, dProgressMap: newMap };
    }
    case "UPDATE_UPLOAD_PROGRESS_DATA": {
      const {
        activityId,
        imageName,
        progress,
        uploadSpeed,
        secondsRemaining,
      } = action.payload;
      const key = `${activityId}_${imageName}`;

      console.log(
        `[UPLOADPROGRESS] found progress of ${key} progress:${
          state.dProgressMap[key]
        }`
      );
      const newMap = { ...state.dProgressMap };
      newMap[key] = {
        progress: progress,
        uploadSpeed: uploadSpeed,
        secondsRemaining: secondsRemaining,
      };
      console.log(
        `[UPLOADPROGRESS] updating progress of ${key} progress:${newMap[key]}`
      );
      return { ...state.dProgressMap, dProgressMap: newMap };
    }
    case "CLEAR_UPLOAD_PROGRESS_DATA":
      return clearState;
    default:
      return state;
  }
};
