'use strict';

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

var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');

var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);

var _utils = require('./utils');

var _actionTypes = require('./action-types');

var actionTypes = _interopRequireWildcard(_actionTypes);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var transformPayload = exports.transformPayload = function transformPayload(resourceName, actionType, args) {
  switch (actionType) {
    case actionTypes.SEARCH:
      {
        var _args = (0, _slicedToArray3.default)(args, 1),
            searchString = _args[0];

        return [{ resourceName: resourceName, searchString: searchString }];
      }
    default:
      return args;
  }
};

exports.default = function (resourceName, getters) {
  var res = {};
  (0, _utils.normalizeMap)(getters).forEach(function (_ref) {
    var key = _ref.key,
        val = _ref.val;

    res[key] = function mappedGetter() {
      var namespace = (0, _utils.normalizeNamespaceName)(this.$store.search._base);
      return this.$store.getters['' + namespace + val](resourceName);
    };
  });

  return res;
};