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 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, getUniqueId } from '@pisell/utils';
import { globalConfig } from '@pisell/materials';
import { getAvailableMaxAmount } from "../../utils";
var voucherTime = function voucherTime(data) {
  var config = globalConfig.getConfig();
  if (data !== null && data !== void 0 && data.expire_date) {
    return formatDate(data === null || data === void 0 ? void 0 : data.expire_date, (config === null || config === void 0 ? void 0 : config.locale) === 'en' ? 'DD/MM/YYYY' : 'YYYY-MM-DD');
  }
  return locales.getText('tocPay.text.walletPassPermanent');
};
export var formatMachineCodeServer2CardList = function formatMachineCodeServer2CardList(data) {
  var selectId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  return (data || []).map(function (item) {
    var _item$shop, _item$unified_message, _item$product, _item$custom_schedule, _item$metadata;
    return {
      id: item.id,
      name: item.product_name,
      storeName: (_item$shop = item.shop) === null || _item$shop === void 0 ? void 0 : _item$shop.name,
      balance: item.balance_par_value,
      redeem: getAvailableMaxAmount(item),
      showRedeem: selectId.includes(item.id),
      showBalanceSymbol: item.tag !== 'point_card',
      // balanceTitle: item.tag !== 'point_card' ? "" : "",
      // redeemTitle: item.tag !== 'point_card' ? "" : "",
      showDetail: false,
      showQrCode: false,
      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,
      scheduleList: ((_item$custom_schedule = item.custom_schedule_snapshot) === null || _item$custom_schedule === void 0 ? void 0 : _item$custom_schedule.data) || [],
      validDateBySchedule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.validity_type) === 'custom_schedule_validity'
    };
  });
};
export var getDataByIds = function getDataByIds(arr, ids) {
  return arr.filter(function (item) {
    return ids.includes(item.id);
  });
};

/**
 * 判断是否是wallet code
 * @param val 
 * @returns 
 */
export var getIsWalletCode = function getIsWalletCode(val) {
  return val.startsWith('WL');
};
export var formatWalletPassWithUniquePaymentNumber = function formatWalletPassWithUniquePaymentNumber(currentWalletPass) {
  return _objectSpread(_objectSpread({}, currentWalletPass), {}, {
    cards: ((currentWalletPass === null || currentWalletPass === void 0 ? void 0 : currentWalletPass.cards) || []).map(function (item) {
      return _objectSpread(_objectSpread({}, item), {}, {
        metadata: _objectSpread(_objectSpread({}, item.metadata || {}), {}, {
          unique_payment_number: getUniqueId()
        })
      });
    })
  });
};