import { formatDate, locales } 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');
};