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/components/wallet/Voucher/index.tsx
var Voucher_exports = {};
__export(Voucher_exports, {
  default: () => Voucher_default
});
module.exports = __toCommonJS(Voucher_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_model = require("./model");
var import_WalletCard = __toESM(require("../components/WalletCard"));
var import_useWalletCard = require("../hooks/useWalletCard");
var import_utils = require("@pisell/utils");
var import_DetailContext = require("../DetailContext");
var import_index = require("./index.less");
var { Title } = import_materials.Typography;
var Voucher = (0, import_model.Provider)((props) => {
  const { globalState, setGlobalState } = props;
  const { product_voucher = [] } = globalState;
  const recordViewRef = (0, import_react.useRef)(null);
  const { openDetail, renderDetail } = (0, import_DetailContext.useDetail)();
  const {
    platform,
    isEmpty,
    state,
    handleRowClick,
    renderCardDetail,
    formatData
  } = (0, import_useWalletCard.useWalletCard)({
    globalState,
    setGlobalState,
    walletContext: (0, import_react.useContext)(import_model.Context),
    cardList: product_voucher,
    cardType: "product_voucher"
  });
  (0, import_react.useEffect)(() => {
    if (globalState.setup !== "detail" && recordViewRef.current) {
      recordViewRef.current.closeDetailModal();
    }
  }, [globalState.setup]);
  const renderItem = (item) => /* @__PURE__ */ import_react.default.createElement(
    import_WalletCard.default,
    {
      balanceTitle: item.tag === "good_pass" ? import_utils.locales.getText("page.wallet.goodPass") : void 0,
      item,
      currentId: globalState.currentId,
      onClick: () => {
        setGlobalState({
          type: "setState",
          payload: { currentId: item.id }
        });
      }
    }
  );
  if (isEmpty) {
    return /* @__PURE__ */ import_react.default.createElement(import_materials.PisellEmpty, null);
  }
  const handleBack = (0, import_react.useCallback)(() => {
    if (recordViewRef.current) {
      recordViewRef.current.closeDetailModal();
    }
    setGlobalState({
      setup: "list"
    });
  }, [recordViewRef, setGlobalState]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, platform !== "pc" && /* @__PURE__ */ import_react.default.createElement(Title, { className: "wallet-voucher-title" }, import_utils.locales.getText("page.wallet.voucher")), /* @__PURE__ */ import_react.default.createElement(
    import_materials.CardMetricItem,
    {
      title: import_utils.locales.getText("page.wallet.voucherBalance"),
      style: { margin: "8px 0 24px" },
      hint: false,
      tags: false,
      number: state.total
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_materials.RecordView,
    {
      ref: recordViewRef,
      mobilePadDetailModalDisplay: true,
      leftSpan: 9,
      rightSpan: 15,
      gutter: 20,
      onRowClick: (currentDetail) => {
        setGlobalState({
          currentId: currentDetail.id || "",
          currentDetail,
          setup: "detail"
          // 设置状态为detail
        });
        const detailWithProps = {
          ...currentDetail,
          showWalletBar: platform === "h5",
          // 添加显示WalletBar的标志
          onBack: handleBack
          // 添加返回处理函数
        };
        openDetail(detailWithProps);
      },
      modalWrapStyle: {
        overflowY: "auto",
        top: 68,
        height: "calc(100% - 68px)",
        zIndex: 998
      },
      pcDetailModalDisplay: platform === "h5" ? true : false,
      padDetailModalDisplay: true,
      isShowClode: false,
      split: false,
      children: null,
      detail: renderCardDetail(),
      emptyButtons: [],
      doubleList: true,
      doubleListSource: formatData(),
      dataSource: product_voucher,
      renderItem
    }
  ));
});
var Voucher_default = Voucher;
