import {
  ADD_VIDEOS_TO_STATE
} from '../actions/action_types';

export default function(state={}, action) {
  switch (action.type) {
    case ADD_VIDEOS_TO_STATE:
      let clonedState = Object.assign({}, state);
      if (!clonedState.allVideos) {
        clonedState.allVideos = {};
      }
      const videosToAdd = action.payload;
      videosToAdd.forEach(video => {
        if (!clonedState.allVideos.hasOwnProperty(video.id)) {
          clonedState.allVideos[video.id] = video;
        }
      });
      return clonedState;
    default:
      return state;
  }
}