Liferay.Loader.define("commerce-frontend-js@3.0.26/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");

    /**
     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
     *
     * This library is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Lesser General Public License as published by the Free
     * Software Foundation; either version 2.1 of the License, or (at your option)
     * any later version.
     *
     * This library is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
     * details.
     */
    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"), 'editCommerceOrder');
      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(_ref2) {
      var itemsQuantity = _ref2.itemsQuantity,
          subtotalDiscountValueFormatted = _ref2.subtotalDiscountValueFormatted,
          subtotalFormatted = _ref2.subtotalFormatted,
          totalDiscountValueFormatted = _ref2.totalDiscountValueFormatted,
          totalFormatted = _ref2.totalFormatted;
      return [{
        label: Liferay.Language.get('quantity'),
        value: itemsQuantity
      }, {
        label: Liferay.Language.get('subtotal'),
        value: subtotalFormatted
      }, {
        label: Liferay.Language.get('subtotal-discount'),
        value: subtotalDiscountValueFormatted
      }, {
        label: Liferay.Language.get('order-discount'),
        value: totalDiscountValueFormatted
      }, {
        label: Liferay.Language.get('total'),
        style: 'big',
        value: totalFormatted
      }];
    }

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