import * as types from '../actions/types';

const initialState = {
  messages: []
};

export default (state = initialState, action) => {
  switch (action.type) {
    case types.NOTICE_MESSAGE_ERROR:
      return {
        ...state,
        messages: state.messages.concat([{
          message: action.message,
          type: 'error'
        }])
      };
    case types.NOTICE_MESSAGE_SUCCESS:
      return {
        ...state,
        messages: state.messages.concat([{
          message: action.message,
          type: 'success'
        }])
      };
    case types.NOTICE_MESSAGE_REMOVE:
      return {
        ...state,
        messages: state.messages.filter((message) => message !== action.message)
      };
    case types.NOTICE_MESSAGE_CLEAR:
      return initialState;
    default:
      return state;
  }
};
