"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _immutable = _interopRequireDefault(require("immutable"));

var _reduxActions = require("redux-actions");

var _actions = require("./actions");

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

var _handleActions;

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

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; }

var initialState = _immutable["default"].Map();

var cartReducer = (0, _reduxActions.handleActions)((_handleActions = {}, _defineProperty(_handleActions, _actions.receiveCartData, function (state, _ref) {
  var payload = _ref.payload;
  var replaceState = !state || !payload || state.get('id') !== payload.id;
  return replaceState ? _immutable["default"].fromJS(payload) : state.mergeWith(_utils.skipListsMerger, payload);
}), _defineProperty(_handleActions, _actions.receiveCartPaymentMethods, function (state, _ref2) {
  var payload = _ref2.payload;
  return state.mergeDeep({
    paymentMethods: payload
  });
}), _defineProperty(_handleActions, _actions.receiveCartShippingMethods, function (state, _ref3) {
  var payload = _ref3.payload;
  return state.mergeDeep({
    shippingMethods: payload
  });
}), _handleActions), null); // TODO: This reducer isn't smart enough to reduce child categories into the root
// 'categories' redux branch, we should make it do that.

var categoryReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveCategoryData, function (state, _ref4) {
  var payload = _ref4.payload;
  return state.mergeDeep(payload);
}), initialState);
var customerReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveCustomerData, function (state, _ref5) {
  var payload = _ref5.payload;
  return payload ? (state || initialState).mergeDeep(payload) : null;
}), null);
var orderReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveOrderData, function (state, _ref6) {
  var payload = _ref6.payload;
  return state.mergeDeep(payload);
}), initialState);
var productReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveProductData, function (state, _ref7) {
  var payload = _ref7.payload;
  return state.mergeDeep(payload);
}), initialState);
var productSearchReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveProductSearchData, function (state, _ref8) {
  var payload = _ref8.payload;
  return state.mergeDeep(payload);
}), initialState);
var storeReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveStoreData, function (state, _ref9) {
  var payload = _ref9.payload;
  return state.mergeDeep(payload);
}), initialState);
var storeSearchReducer = (0, _reduxActions.handleActions)(_defineProperty({}, _actions.receiveStoreSearchData, function (state, _ref10) {
  var payload = _ref10.payload;
  return state.mergeDeep(payload);
}), initialState); // const simpleReducer = (state = null) => state

var _default = {
  cart: cartReducer,
  categories: categoryReducer,
  customer: customerReducer,
  orders: orderReducer,
  products: productReducer,
  productSearches: productSearchReducer,
  stores: storeReducer,
  storeSearches: storeSearchReducer
};
exports["default"] = _default;