function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { formatDate, locales } from '@pisell/utils';
import { globalConfig } from "@pisell/materials";
import Decimal from 'decimal.js';
// 获取walletPass可用最大金额
export var getAvailableMaxAmount = function getAvailableMaxAmount(data) {
  return data.tag !== 'point_card' ? data.available_max_amount : data === null || data === void 0 ? void 0 : data.recommended_usage_amount;
};
export var voucherTime = function voucherTime(data) {
  var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'expire_date';
  var config = globalConfig.getConfig();
  if (data[key]) {
    return formatDate(data[key], (config === null || config === void 0 ? void 0 : config.locale) === 'en' ? 'DD/MM/YYYY' : 'YYYY-MM-DD');
  }
  return locales.getText('pisell2.text.walletPassPermanent');
};
export var formatMachineCodeServer2CardList = function formatMachineCodeServer2CardList(data) {
  var selectId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  var otherProps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  return (data || []).map(function (item) {
    var _item$unified_message, _item$product;
    return _objectSpread({
      id: item.id,
      name: item.product_name,
      // storeName: item.shop?.name,
      balance: item.balance_par_value,
      cardStatus: false,
      redeem: item.edit_current_amount !== undefined ? item.edit_current_amount : getAvailableMaxAmount(item),
      maxRedeem: getAvailableMaxAmount(item),
      showRedeem: selectId.includes(item.id),
      showStoreName: false,
      showBalanceSymbol: item.tag !== 'point_card',
      showActions: false,
      showDetail: false,
      showQrCode: false,
      showStatus: true,
      code: item.code,
      disabled: !item.unified_available_status,
      disabledReason: (_item$unified_message = item.unified_messages) === null || _item$unified_message === void 0 ? void 0 : _item$unified_message.title,
      cover: (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.cover,
      qrCode: item.code,
      validDate: voucherTime(item),
      originData: item
    }, otherProps);
  });
};
export var formatDiscountWalletData = function formatDiscountWalletData(data) {
  var selectId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  return (data || []).map(function (item) {
    var _item$product2;
    var name = "";
    var storeName = "";
    if (item.tag === 'product_discount_card') {
      name = locales.getText('pisell2.checkout.discount.percentage.off')(item.par_value);
      storeName = item.product_name;
    } else if (item.tag === 'good_pass') {
      var _locales$getText;
      name = item.product_name;
      var left = Number(item.balance) || 0;
      var use = 1;
      // 使用多语言文本格式化 storeName
      storeName = (_locales$getText = locales.getText('pisell2.checkout.wallet-pass.good-pass.format')) === null || _locales$getText === void 0 ? void 0 : _locales$getText(left, use);
    } else {
      name = item.product_name;
    }
    return _objectSpread(_objectSpread({}, item), {}, {
      id: item.id,
      name: name,
      storeName: storeName,
      balance: item.balance_par_value,
      showBalance: false,
      showStoreName: true,
      redeem: getAvailableMaxAmount(item),
      showRedeem: selectId.includes(item.id),
      showBalanceSymbol: item.tag !== 'point_card',
      showActions: false,
      error: item.isDisabled,
      showDisabledReason: false,
      showDetail: false,
      showQrCode: false,
      code: item.code,
      disabled: item.isDisabled,
      showStatus: true,
      cardStatus: item.isDisabled ? 'conflict' : undefined,
      cover: (_item$product2 = item.product) === null || _item$product2 === void 0 ? void 0 : _item$product2.cover,
      qrCode: item.code,
      validDate: voucherTime(item, 'expire_time'),
      originData: item,
      enableEditAmount: false
    });
  });
};

// WalletPassUsageUnit类型定义

/**
 * 根据WalletPassUsage配置，将传入的WalletPass面额转换为货币金额
 */
export var getPointCardAmount = function getPointCardAmount(walletPassValue, walletPassUsageUnit) {
  // 无有效积分比例数据，按1比1处理
  if (!walletPassUsageUnit.points || !walletPassUsageUnit.price) {
    return new Decimal(walletPassValue).toFixed(2);
  }

  // 示例:
  // 3price <==> 5points 基础对等关系
  // walletPassValue = 15points
  // 计算积分面额转换后的货币金额: 15points / 5points * 3price = 9price

  // 计算walletPassValue 与 积分面额基础数据的比例
  var baseRatio = new Decimal(walletPassValue).div(walletPassUsageUnit.points);

  // 计算当前实际付款的货币金额
  // 保留两位小数，向下舍入（不四舍五入，与PHP的bcmul第三位舍去行为一致）
  return baseRatio.mul(walletPassUsageUnit.price).toFixed(2, Decimal.ROUND_DOWN);
};

// 检查两个数组是否包含相同的元素
export var isSameContent = function isSameContent(arr1, arr2) {
  return _toConsumableArray(arr1).sort().join(',') === _toConsumableArray(arr2).sort().join(',');
};