Liferay.Loader.define("commerce-frontend-js@3.0.33/components/mini_cart/util/index", ['module', 'exports', 'require', './constants'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.isNonnull = isNonnull;
    exports.collectDiscountLevels = collectDiscountLevels;
    exports.parseOptions = parseOptions;
    exports.regenerateOrderDetailURL = regenerateOrderDetailURL;
    exports.summaryDataMapper = summaryDataMapper;
    exports.hasErrors = hasErrors;

    var _constants = require("./constants");

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

    function isNonnull() {
      for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) {
        values[_key] = arguments[_key];
      }

      return !!values.find(function (value) {
        return parseFloat(value) > 0;
      });
    }

    function collectDiscountLevels(price) {
      return Object.keys(price).reduce(function (levels, key) {
        if (key.startsWith(_constants.DISCOUNT_LEVEL_PREFIX)) {
          levels.push(price[key].toFixed(2));
        }

        return levels;
      }, []);
    }

    function parseOptions(stringifiedJSON) {
      var options;

      try {
        options = JSON.parse(stringifiedJSON);
      } catch (ignore) {
        options = '';
      }

      return Array.isArray(options) ? options.map(function (_ref) {
        var value = _ref.value;
        return "".concat(value);
      }).join(', ') : options;
    }

    function generatedOrderDetailURL() {
      var baseURL = new URL("".concat(Liferay.ThemeDisplay.getCanonicalURL()).concat(_constants.ORDER_DETAILS_ENDPOINT));
      baseURL.searchParams.append('p_p_id', _constants.DEFAULT_ORDER_DETAILS_PORTLET_ID);
      baseURL.searchParams.append('p_p_lifecycle', '0');
      baseURL.searchParams.append("_".concat(_constants.DEFAULT_ORDER_DETAILS_PORTLET_ID, "_mvcRenderCommandName"), '/commerce_open_order_content/edit_commerce_order');
      baseURL.searchParams.append("_".concat(_constants.DEFAULT_ORDER_DETAILS_PORTLET_ID, "_commerceOrderUuid"), '0');
      return baseURL;
    }

    function regenerateOrderDetailURL(orderDetailURL, orderUUID) {
      var originalURL = orderDetailURL ? new URL(orderDetailURL) : generatedOrderDetailURL();
      originalURL.searchParams.set("_".concat(_constants.DEFAULT_ORDER_DETAILS_PORTLET_ID, "_").concat(_constants.ORDER_UUID_PARAMETER), orderUUID);
      return originalURL.toString();
    }

    function summaryDataMapper(summary) {
      return Object.keys(summary).reduce(function (values, key) {
        var summaryItem = {
          value: summary[key]
        };

        switch (key) {
          case 'itemsQuantity':
            values.push(_objectSpread({
              label: Liferay.Language.get('quantity')
            }, summaryItem));
            break;

          case 'subtotalFormatted':
            values.push(_objectSpread({
              label: Liferay.Language.get('subtotal')
            }, summaryItem));
            break;

          case 'totalDiscountValueFormatted':
            values.push(_objectSpread({
              label: Liferay.Language.get('order-discount')
            }, summaryItem));
            break;

          case 'totalFormatted':
            values.push(_objectSpread({
              label: Liferay.Language.get('total'),
              style: 'big'
            }, summaryItem));
            break;

          default:
            break;
        }

        return values;
      }, []);
    }

    function hasErrors(cartItems) {
      return !!cartItems.find(function (_ref2) {
        var errorMessages = _ref2.errorMessages;
        return !!errorMessages;
      });
    }
    //# sourceMappingURL=index.js.map
  }
});
//# sourceMappingURL=index.js.map