Liferay.Loader.define("commerce-bom-admin-web@4.0.30/js/reducers/area.es", ['module', 'exports', 'require', '../actions/app.es', '../actions/area.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = reducer;
    exports.initialState = void 0;

    var _app = require("../actions/app.es");

    var _area = require("../actions/area.es");

    function _objectWithoutProperties(source, excluded) {
      if (source == null) return {};var target = _objectWithoutPropertiesLoose(source, excluded);var key, i;if (Object.getOwnPropertySymbols) {
        var sourceSymbolKeys = Object.getOwnPropertySymbols(source);for (i = 0; i < sourceSymbolKeys.length; i++) {
          key = sourceSymbolKeys[i];if (excluded.indexOf(key) >= 0) continue;if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;target[key] = source[key];
        }
      }return target;
    }

    function _objectWithoutPropertiesLoose(source, excluded) {
      if (source == null) return {};var target = {};var sourceKeys = Object.keys(source);var key, i;for (i = 0; i < sourceKeys.length; i++) {
        key = sourceKeys[i];if (excluded.indexOf(key) >= 0) continue;target[key] = source[key];
      }return target;
    }

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    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 = {
      availableProducts: [],
      highlightedDetail: null,
      id: null,
      imageUrl: null,
      mappedProducts: [],
      name: null,
      spotFormData: null,
      spots: []
    };
    exports.initialState = initialState;

    function reducer() {
      var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
      var action = arguments.length > 1 ? arguments[1] : undefined;

      switch (action.type) {
        case _app.actionDefinition.INITIALIZE_APP_DATA:
          return _objectSpread(_objectSpread({}, state), {}, {
            id: action.payload.areaId
          });

        case _area.actionDefinition.HIGHLIGHT_DETAIL:
          return _objectSpread(_objectSpread({}, state), {}, {
            highlightedDetail: action.payload
          });

        case _area.actionDefinition.RESET_FORM_DATA:
          return _objectSpread(_objectSpread({}, state), {}, {
            spotFormData: null
          });

        case _area.actionDefinition.SELECT_SPOT:
          {
            var _state$spots$reduce = state.spots.reduce(function (found, spot) {
              return found || spot.id === action.payload && spot;
            }, null),
                productId = _state$spots$reduce.productId,
                spotData = _objectWithoutProperties(_state$spots$reduce, ["productId"]);

            var relatedProduct = state.mappedProducts.reduce(function (acc, el) {
              return acc || el.id === productId && el;
            }, null);
            var spotFormData = {
              id: action.payload,
              number: spotData.number,
              position: spotData.position,
              productId: relatedProduct.id,
              query: relatedProduct.name
            };
            return _objectSpread(_objectSpread({}, state), {}, {
              spotFormData: _objectSpread({
                changed: false,
                originalData: spotFormData,
                state: 'edit'
              }, spotFormData)
            });
          }

        case _area.actionDefinition.UPDATE_FORM_VALUE:
          {
            var key = action.payload.key;
            var value = action.payload.value;
            var changed = state.spotFormData.state === 'edit' ? state.spotFormData.originalData[key] !== value : true;
            return _objectSpread(_objectSpread({}, state), {}, {
              spotFormData: _objectSpread(_objectSpread({}, state.spotFormData), {}, _defineProperty({
                changed: changed
              }, key, value))
            });
          }

        case _area.actionDefinition.UNSELECT_SPOT:
          return _objectSpread(_objectSpread({}, state), {}, {
            spotFormData: null
          });

        case _area.actionDefinition.CREATE_SPOT:
          return _objectSpread(_objectSpread({}, state), {}, {
            spotFormData: {
              position: action.payload,
              state: 'create'
            }
          });

        case _area.actionDefinition.GET_AREA_FULFILLED:
          {
            var _action$payload$data = action.payload.data,
                imageUrl = _action$payload$data.imageUrl,
                name = _action$payload$data.name,
                products = _action$payload$data.products,
                spots = _action$payload$data.spots;
            return _objectSpread(_objectSpread({}, state), {}, {
              imageUrl: imageUrl,
              mappedProducts: products || [],
              name: name,
              spots: spots || []
            });
          }

        case _area.actionDefinition.GET_PRODUCTS_FULFILLED:
          return _objectSpread(_objectSpread({}, state), {}, {
            availableProducts: action.payload || []
          });

        case _area.actionDefinition.RESET_PRODUCTS:
          return _objectSpread(_objectSpread({}, state), {}, {
            availableProducts: []
          });

        case _area.actionDefinition.DELETE_SPOT_REJECTED:
        case _area.actionDefinition.SUBMIT_NEW_SPOT_REJECTED:
        case _area.actionDefinition.SUBMIT_SPOT_CHANGES_REJECTED:
          return _objectSpread(_objectSpread({}, state), {}, {
            spotFormData: null
          });

        case _area.actionDefinition.DELETE_SPOT_FULFILLED:
        case _area.actionDefinition.SUBMIT_NEW_SPOT_FULFILLED:
        case _area.actionDefinition.SUBMIT_SPOT_CHANGES_FULFILLED:
          return _objectSpread(_objectSpread({}, state), {}, {
            spotFormData: null
          });

        default:
          return state;
      }
    }
    //# sourceMappingURL=area.es.js.map
  }
});
//# sourceMappingURL=area.es.js.map