'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.readVocabularyItems = exports.READ_VOCABULARY_ITEMS_REJECTED = exports.READ_VOCABULARY_ITEMS_FULFILLED = exports.READ_VOCABULARY_ITEMS_STARTED = undefined;

var _cspace = require('./cspace');

var _cspace2 = _interopRequireDefault(_cspace);

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

var READ_VOCABULARY_ITEMS_STARTED = exports.READ_VOCABULARY_ITEMS_STARTED = 'READ_VOCABULARY_ITEMS_STARTED';
var READ_VOCABULARY_ITEMS_FULFILLED = exports.READ_VOCABULARY_ITEMS_FULFILLED = 'READ_VOCABULARY_ITEMS_FULFILLED';
var READ_VOCABULARY_ITEMS_REJECTED = exports.READ_VOCABULARY_ITEMS_REJECTED = 'READ_VOCABULARY_ITEMS_REJECTED';

var readVocabularyItems = exports.readVocabularyItems = function readVocabularyItems(vocabularyName) {
  return function (dispatch) {
    dispatch({
      type: READ_VOCABULARY_ITEMS_STARTED,
      meta: {
        vocabularyName: vocabularyName
      }
    });

    var config = {
      params: {
        pgSz: '0',
        wf_deleted: false
      }
    };

    return (0, _cspace2.default)().read('vocabularies/urn:cspace:name(' + vocabularyName + ')/items', config).then(function (response) {
      return dispatch({
        type: READ_VOCABULARY_ITEMS_FULFILLED,
        payload: response,
        meta: {
          vocabularyName: vocabularyName
        }
      });
    }).catch(function (error) {
      return dispatch({
        type: READ_VOCABULARY_ITEMS_REJECTED,
        payload: error,
        meta: {
          vocabularyName: vocabularyName
        }
      });
    });
  };
};