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/PointCard/index.tsx
var PointCard_exports = {};
__export(PointCard_exports, {
  default: () => PointCard_default
});
module.exports = __toCommonJS(PointCard_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_model = require("./model");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_utils = require("@pisell/utils");
var import_locales = __toESM(require("../locales"));
var import_index = require("./index.less");
var import_DetailContext = require("../DetailContext");
var import_WalletCard = __toESM(require("../components/WalletCard"));
var { Title } = import_materials.Typography;
var RechargeableCard = (0, import_model.Provider)((props) => {
  var _a, _b, _c;
  const { globalState, setGlobalState } = props;
  const { currentId, currentDetail, point_card } = globalState;
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const context = (0, import_useEngineContext.default)();
  const utils = context.appHelper.utils || {};
  const dvaStore = (_b = (_a = utils == null ? void 0 : utils.getStore) == null ? void 0 : _a.call(utils)) == null ? void 0 : _b.getState();
  const recordViewRef = (0, import_react.useRef)(null);
  const { openDetail, renderDetail } = (0, import_DetailContext.useDetail)();
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
  }, []);
  const platform = (0, import_utils.isMobile)() ? "h5" : "pc";
  const renderItem = (item) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_WalletCard.default,
      {
        item,
        balanceTitle: import_utils.locales.getText("page.wallet.pointCard"),
        currentId,
        onClick: () => {
          setGlobalState({
            type: "setState",
            payload: {
              currentId: item.id
            }
          });
        }
      }
    );
  };
  (0, import_react.useEffect)(() => {
    const enabledCards = point_card.filter(
      (item) => item.limit_status === "enable"
    );
    const total = enabledCards.reduce(
      (sum, item) => sum + Number(item.balance),
      0
    );
    dispatch({
      type: "setState",
      payload: {
        total
      }
    });
  }, [point_card]);
  const detail = () => {
    if (!(currentDetail == null ? void 0 : currentDetail.id)) return null;
    const detailWithProps = {
      ...currentDetail,
      showWalletBar: platform === "h5",
      // 添加显示WalletBar的标志
      onBack: handleBack
      // 添加返回处理函数
    };
    return renderDetail(detailWithProps);
  };
  const handleBack = (0, import_react.useCallback)(() => {
    if (recordViewRef.current) {
      recordViewRef.current.closeDetailModal();
    }
    setGlobalState({
      setup: "list"
    });
  }, [recordViewRef, setGlobalState]);
  const isEmpty = !point_card.some(
    (item) => item.limit_status === "enable"
  );
  import_utils.locales.init(import_locales.default, ((_c = dvaStore == null ? void 0 : dvaStore.core) == null ? void 0 : _c.translateLocale) || "en");
  const formatData = () => {
    let available = {
      title: import_utils.locales.getText("page.wallet.available"),
      dataSource: point_card.filter(
        (item) => item.limit_status === "enable"
      )
    };
    const unavailable = {
      title: import_utils.locales.getText("page.wallet.unavailable"),
      dataSource: point_card.filter(
        (item) => item.limit_status === "disable"
      )
    };
    return [available, unavailable];
  };
  (0, import_react.useEffect)(() => {
    var _a2;
    if (globalState.setup !== "detail") {
      (_a2 = recordViewRef.current) == null ? void 0 : _a2.closeDetailModal();
    }
  }, [globalState.setup]);
  return isEmpty ? /* @__PURE__ */ import_react.default.createElement(import_materials.PisellEmpty, null) : /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, platform !== "pc" && /* @__PURE__ */ import_react.default.createElement(Title, { className: "wallet-pointCard-title" }, import_utils.locales.getText("page.wallet.pointCard")), /* @__PURE__ */ import_react.default.createElement(
    import_materials.CardMetricItem,
    {
      title: import_utils.locales.getText("page.wallet.points"),
      style: { margin: "8px 0 24px" },
      hint: false,
      tags: false,
      number: state.total,
      showCurrencySymbol: false
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_materials.RecordView,
    {
      ref: recordViewRef,
      mobilePadDetailModalDisplay: true,
      leftSpan: 9,
      rightSpan: 15,
      gutter: 20,
      onRowClick: (currentDetail2) => {
        setGlobalState({
          currentId: currentDetail2.id || "",
          currentDetail: currentDetail2,
          setup: "detail"
          // 设置状态为detail
        });
        const detailWithProps = {
          ...currentDetail2,
          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: detail(),
      emptyButtons: [],
      doubleList: true,
      doubleListSource: formatData(),
      dataSource: point_card,
      renderItem: (value) => renderItem(value)
    }
  ));
});
var PointCard_default = RechargeableCard;
