import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
import { Record, List } from 'immutable';
import { Utils } from '@kineticdata/bundle-common';
var noPayload = Utils.noPayload,
    withPayload = Utils.withPayload;
var ns = Utils.namespaceBuilder('techbar/export');
export var 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')
};
export var 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)
};
export var State = Record({
  exporting: false,
  data: null,
  error: null
});
export var 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', List()).set('error', false).set('exporting', true);

    case types.FETCH_EXPORT_SUBMISSIONS_SUCCESS:
      return state.update('data', function (data) {
        return data.push.apply(data, _toConsumableArray(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;
  }
};