var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/walletPassGallery/components/passList/index.tsx
var passList_exports = {};
__export(passList_exports, {
  default: () => passList_default
});
module.exports = __toCommonJS(passList_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var PassList = (props) => {
  var _a;
  const {
    dataSource = [],
    value,
    onChange,
    valuePropName = "id",
    hasMore,
    onLoadMore,
    loading,
    onEditHolder
  } = props;
  const context = (0, import_useEngineContext.default)();
  const utils = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const { isTerminal, isApp } = utils;
  const isTerminalEnv = (typeof isTerminal === "function" ? isTerminal() : !!isTerminal) || (isApp == null ? void 0 : isApp());
  const _loadMore = /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      style: {
        textAlign: "center",
        marginBottom: 12,
        height: 32,
        lineHeight: "32px"
      }
    },
    hasMore ? /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { onClick: onLoadMore, loading }, import_utils.locales.getText("wallet-pass-gallery.viewMore")) : /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        style: {
          color: "#999"
        }
      },
      import_utils.locales.getText("wallet-pass-gallery.allLoaded")
    )
  );
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.List,
    {
      className: "pisell-wallet-pass-gallery_list",
      itemLayout: "horizontal",
      dataSource,
      split: false,
      loadMore: _loadMore,
      loading,
      renderItem: (item, index) => {
        const {
          id,
          tag,
          product_title = "",
          balance = 0,
          code = "",
          encoded = "",
          expire_date = "",
          shop = { name: "" },
          limit_status,
          product_cover = "",
          par_value = "",
          unified_available_status,
          unified_messages = {},
          holder,
          ...rest
        } = item;
        const itemValue = item == null ? void 0 : item[valuePropName];
        const { title: disabledReason = "" } = unified_messages;
        const { name: storeName = "" } = shop;
        const isDiscountCard = tag === "product_discount_card";
        return /* @__PURE__ */ import_react.default.createElement(import_antd.List.Item, { style: { padding: 0 } }, /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            style: { cursor: "pointer", width: "100%" },
            role: "button",
            onClick: () => onChange == null ? void 0 : onChange(itemValue)
          },
          /* @__PURE__ */ import_react.default.createElement(
            import_materials.PisellWalletPassCard,
            {
              ...rest,
              balanceTitle: tag === "good_pass" ? import_utils.locales.getText("wallet-pass-gallery.goodPass") : void 0,
              showDetail: false,
              showRedeem: false,
              showQrCode: true,
              showBalance: !isDiscountCard,
              cover: product_cover,
              disabled: unified_available_status === 0,
              showDisabledReason: unified_available_status === 0,
              disabledReason,
              style: { marginBottom: 16, width: "100%" },
              showBalanceSymbol: !["point_card", "good_pass"].includes(tag),
              active: value === itemValue,
              name: product_title,
              qrCode: code,
              storeName,
              balance: Number(balance),
              discount: isDiscountCard ? Number(par_value) : void 0,
              showDiscount: isDiscountCard,
              code: encoded,
              validDate: expire_date,
              holder,
              onSetHolder: isTerminalEnv ? void 0 : () => {
                var _a2;
                onEditHolder == null ? void 0 : onEditHolder({
                  wallet_pass_detail_id: id,
                  customer_id: holder == null ? void 0 : holder.customer_id,
                  form_id: (_a2 = holder == null ? void 0 : holder.metadata) == null ? void 0 : _a2.custom_id
                });
              }
            }
          )
        ));
      }
    }
  ));
};
var passList_default = PassList;
