import React, { useMemo } from 'react';
import { PisellWalletPassCard } from '@pisell/materials';
import { isMobile } from '@pisell/utils';
/**
 * 钱包卡片组件
 * 统一各类钱包卡的渲染逻辑
 */
var WalletCard = function WalletCard(_ref) {
  var item = _ref.item,
    currentId = _ref.currentId,
    _ref$isDiscountCard = _ref.isDiscountCard,
    isDiscountCard = _ref$isDiscountCard === void 0 ? false : _ref$isDiscountCard,
    onClick = _ref.onClick,
    balanceTitle = _ref.balanceTitle;
  // 解构卡片数据
  var id = item.id,
    tag = item.tag,
    _item$product_title = item.product_title,
    product_title = _item$product_title === void 0 ? '' : _item$product_title,
    _item$balance = item.balance,
    balance = _item$balance === void 0 ? 0 : _item$balance,
    _item$code = item.code,
    code = _item$code === void 0 ? '' : _item$code,
    _item$encoded = item.encoded,
    encoded = _item$encoded === void 0 ? '' : _item$encoded,
    _item$expire_date = item.expire_date,
    expire_date = _item$expire_date === void 0 ? '' : _item$expire_date,
    _item$shop = item.shop,
    shop = _item$shop === void 0 ? {
      name: ''
    } : _item$shop,
    limit_status = item.limit_status,
    _item$product_cover = item.product_cover,
    product_cover = _item$product_cover === void 0 ? '' : _item$product_cover,
    _item$par_value = item.par_value,
    par_value = _item$par_value === void 0 ? '' : _item$par_value,
    _item$unified_message = item.unified_messages,
    unified_messages = _item$unified_message === void 0 ? {} : _item$unified_message;

  // 获取平台
  var platform = useMemo(function () {
    return isMobile() ? 'h5' : 'pc';
  }, []);

  // 获取提示信息
  var _unified_messages$tit = unified_messages.title,
    disabledReason = _unified_messages$tit === void 0 ? '' : _unified_messages$tit;
  var _shop$name = shop.name,
    storeName = _shop$name === void 0 ? '' : _shop$name;

  // 是否为当前选中项
  var isActive = id === currentId && platform === 'pc';
  // 是否禁用
  var isDisabled = limit_status !== 'enable';
  return /*#__PURE__*/React.createElement(PisellWalletPassCard, {
    balanceTitle: balanceTitle,
    showDetail: false,
    showRedeem: false,
    showQrCode: true,
    showBalance: !isDiscountCard,
    cover: product_cover,
    disabled: isDisabled,
    showDisabledReason: isDisabled,
    disabledReason: disabledReason,
    propStyle: {
      marginBottom: 16
    },
    showBalanceSymbol: !['point_card', 'good_pass'].includes(tag),
    active: isActive,
    name: product_title,
    qrCode: code,
    storeName: storeName,
    balance: Number(balance),
    discount: isDiscountCard ? Number(par_value) : undefined,
    showDiscount: isDiscountCard,
    code: encoded,
    validDate: expire_date,
    onClick: onClick
  });
};
export default /*#__PURE__*/React.memo(WalletCard);