'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);

var _findIndex = require('lodash/findIndex');

var _findIndex2 = _interopRequireDefault(_findIndex);

var _constants = require('../constants');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var features = function features() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var action = arguments[1];

  var newState = void 0;
  var index = void 0;
  switch (action.type) {
    case 'ADD_FEATURES':
      return [].concat((0, _toConsumableArray3.default)(state), (0, _toConsumableArray3.default)(action.payload));
    case _constants.EDIT_FEATURE:
      var newFeature = action.payload;
      newState = state.slice(0);
      index = (0, _findIndex2.default)(state, { id: newFeature.id });
      newState[index] = newFeature;
      return newState;
    case _constants.DELETE_FEATURE:
      index = (0, _findIndex2.default)(state, { id: action.payload });
      newState = state.slice(0);
      newState.splice(index, 1);
      return newState;
    case 'REPLACE_FEATURES':
      return action.payload;
  }
  return state;
};

exports.default = features;
//# sourceMappingURL=features.js.map