'use strict';

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

var _vocabulary = require('../actions/vocabulary');

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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

  switch (action.type) {
    case _vocabulary.READ_VOCABULARY_ITEMS_STARTED:
      return Object.assign({}, state, _defineProperty({}, action.meta.vocabularyName, {
        isReadPending: true,
        items: null
      }));
    case _vocabulary.READ_VOCABULARY_ITEMS_FULFILLED:
      return Object.assign({}, state, _defineProperty({}, action.meta.vocabularyName, {
        items: action.payload.data['ns2:abstract-common-list']['list-item']
      }));
    case _vocabulary.READ_VOCABULARY_ITEMS_REJECTED:
      return Object.assign({}, state, _defineProperty({}, action.meta.vocabularyName, {
        error: action.payload
      }));
    default:
      return state;
  }
};

function get(state, vocabularyName) {
  return state[vocabularyName];
}