"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.types = exports.reducer = exports.actions = exports.State = void 0;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm/toConsumableArray"));
var _immutable = require("immutable");
var _bundleCommon = require("@kineticdata/bundle-common");
var noPayload = _bundleCommon.Utils.noPayload,
  withPayload = _bundleCommon.Utils.withPayload;
var ns = _bundleCommon.Utils.namespaceBuilder('techbar/export');
var types = exports.types = {
  FETCH_EXPORT_SUBMISSIONS_REQUEST: ns('FETCH_EXPORT_SUBMISSIONS_REQUEST'),
  FETCH_EXPORT_SUBMISSIONS_SUCCESS: ns('FETCH_EXPORT_SUBMISSIONS_SUCCESS'),
  FETCH_EXPORT_SUBMISSIONS_FAILURE: ns('FETCH_EXPORT_SUBMISSIONS_FAILURE'),
  FETCH_EXPORT_SUBMISSIONS_COMPLETE: ns('FETCH_EXPORT_SUBMISSIONS_COMPLETE')
};
var actions = exports.actions = {
  fetchExportSubmissionsRequest: withPayload(types.FETCH_EXPORT_SUBMISSIONS_REQUEST),
  fetchExportSubmissionsSuccess: withPayload(types.FETCH_EXPORT_SUBMISSIONS_SUCCESS),
  fetchExportSubmissionsFailure: withPayload(types.FETCH_EXPORT_SUBMISSIONS_FAILURE),
  fetchExportSubmissionsComplete: noPayload(types.FETCH_EXPORT_SUBMISSIONS_COMPLETE)
};
var State = exports.State = (0, _immutable.Record)({
  exporting: false,
  data: null,
  error: null
});
var reducer = exports.reducer = function reducer() {
  var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : State();
  var _ref = arguments.length > 1 ? arguments[1] : undefined,
    type = _ref.type,
    payload = _ref.payload;
  switch (type) {
    case types.FETCH_EXPORT_SUBMISSIONS_REQUEST:
      return state.set('data', (0, _immutable.List)()).set('error', false).set('exporting', true);
    case types.FETCH_EXPORT_SUBMISSIONS_SUCCESS:
      return state.update('data', function (data) {
        return data.push.apply(data, (0, _toConsumableArray2["default"])(payload));
      });
    case types.FETCH_EXPORT_SUBMISSIONS_FAILURE:
      return state.set('error', payload).set('exporting', false);
    case types.FETCH_EXPORT_SUBMISSIONS_COMPLETE:
      return state.set('exporting', false);
    default:
      return state;
  }
};