function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/**
 * @title: 计算支付列表的手续费
 * @description: 
 * @param {any} paymentList
 * @param {number} amount
 * @return {*}
 * @Author: zhiwei.Wang
 * @Date: 2024-08-18 09:30
 */
export var calculateSurcharge = function calculateSurcharge(paymentList, amount) {
  return paymentList.map(function (payment) {
    var surcharge_config = payment.surcharge_config,
      currency_symbol = payment.currency_symbol,
      surcharge_text = payment.surcharge_text;

    // 没有手续费展示空
    if (!surcharge_config || surcharge_config.length === 0) {
      payment.surcharge = '';
      return payment;
    }

    // 分别计算出每一项的手续费  百分比 * amount + 固定金额
    var fees = surcharge_config.map(function (config) {
      var _config$percent;
      // 后端字段不统一?, 做下兼容
      var percentageFee = parseFloat((_config$percent = config.percent) !== null && _config$percent !== void 0 ? _config$percent : config.percentage) * Number(amount);
      var totalFee = percentageFee + parseFloat(config.amount);
      return totalFee;
    });

    // 取出最小值和最大值
    var minFee = Math.min.apply(Math, _toConsumableArray(fees));
    var maxFee = Math.max.apply(Math, _toConsumableArray(fees));

    // 如果手续费为0 则展示开孔
    if (minFee === 0 && maxFee === 0) {
      payment.surcharge = '';
      // 一致则只展示最小值
    } else if (minFee === maxFee) {
      payment.surcharge = "".concat(surcharge_text).concat(currency_symbol).concat(minFee.toFixed(2));
    } else {
      // 不一致展示区间
      payment.surcharge = "".concat(surcharge_text).concat(currency_symbol).concat(minFee.toFixed(2), " ~ ").concat(currency_symbol).concat(maxFee.toFixed(2));
    }
    return payment;
  });
};