var _excluded = ["id", "tag", "product_title", "balance", "code", "encoded", "expire_date", "shop", "limit_status", "product_cover", "par_value", "unified_available_status", "unified_messages", "holder"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { Button, List } from 'antd';
import { PisellWalletPassCard } from '@pisell/materials';
import { locales } from '@pisell/utils';
import useEngineContext from "../../../../hooks/useEngineContext";
var PassList = function PassList(props) {
  var _context$appHelper;
  var _props$dataSource = props.dataSource,
    dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
    value = props.value,
    onChange = props.onChange,
    _props$valuePropName = props.valuePropName,
    valuePropName = _props$valuePropName === void 0 ? 'id' : _props$valuePropName,
    hasMore = props.hasMore,
    onLoadMore = props.onLoadMore,
    loading = props.loading,
    onEditHolder = props.onEditHolder;
  var context = useEngineContext();
  var utils = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
  var isTerminal = utils.isTerminal,
    isApp = utils.isApp;
  var isTerminalEnv = (typeof isTerminal === 'function' ? isTerminal() : !!isTerminal) || (isApp === null || isApp === void 0 ? void 0 : isApp());
  var _loadMore = /*#__PURE__*/React.createElement("div", {
    style: {
      textAlign: 'center',
      marginBottom: 12,
      height: 32,
      lineHeight: '32px'
    }
  }, hasMore ? /*#__PURE__*/React.createElement(Button, {
    onClick: onLoadMore,
    loading: loading
  }, locales.getText('wallet-pass-gallery.viewMore')) : /*#__PURE__*/React.createElement("div", {
    style: {
      color: '#999'
    }
  }, locales.getText('wallet-pass-gallery.allLoaded')));
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(List, {
    className: "pisell-wallet-pass-gallery_list",
    itemLayout: "horizontal",
    dataSource: dataSource,
    split: false,
    loadMore: _loadMore,
    loading: loading,
    renderItem: function renderItem(item, index) {
      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,
        unified_available_status = item.unified_available_status,
        _item$unified_message = item.unified_messages,
        unified_messages = _item$unified_message === void 0 ? {} : _item$unified_message,
        holder = item.holder,
        rest = _objectWithoutProperties(item, _excluded);
      // 用于选中状态和变更回调的值（支持自定义属性名）
      var itemValue = item === null || item === void 0 ? void 0 : item[valuePropName];
      // 获取提示信息
      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 isDiscountCard = tag === 'product_discount_card';
      return /*#__PURE__*/React.createElement(List.Item, {
        style: {
          padding: 0
        }
      }, /*#__PURE__*/React.createElement("div", {
        style: {
          cursor: 'pointer',
          width: '100%'
        },
        role: "button",
        onClick: function onClick() {
          return onChange === null || onChange === void 0 ? void 0 : onChange(itemValue);
        }
      }, /*#__PURE__*/React.createElement(PisellWalletPassCard, _extends({}, rest, {
        balanceTitle: tag === 'good_pass' ? locales.getText('wallet-pass-gallery.goodPass') : undefined,
        showDetail: false,
        showRedeem: false,
        showQrCode: true,
        showBalance: !isDiscountCard,
        cover: product_cover,
        disabled: unified_available_status === 0,
        showDisabledReason: unified_available_status === 0,
        disabledReason: disabledReason,
        style: {
          marginBottom: 16,
          width: '100%'
        },
        showBalanceSymbol: !['point_card', 'good_pass'].includes(tag),
        active: value === itemValue,
        name: product_title,
        qrCode: code,
        storeName: storeName,
        balance: Number(balance),
        discount: isDiscountCard ? Number(par_value) : undefined,
        showDiscount: isDiscountCard,
        code: encoded,
        validDate: expire_date,
        holder: holder,
        onSetHolder: isTerminalEnv ? undefined : function () {
          var _holder$metadata;
          onEditHolder === null || onEditHolder === void 0 || onEditHolder({
            wallet_pass_detail_id: id,
            customer_id: holder === null || holder === void 0 ? void 0 : holder.customer_id,
            form_id: holder === null || holder === void 0 || (_holder$metadata = holder.metadata) === null || _holder$metadata === void 0 ? void 0 : _holder$metadata.custom_id
          });
        }
      }))));
    }
  }));
};
export default PassList;