var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/wallet/hooks/useWalletCard.ts
var useWalletCard_exports = {};
__export(useWalletCard_exports, {
  default: () => useWalletCard_default,
  useWalletCard: () => useWalletCard
});
module.exports = __toCommonJS(useWalletCard_exports);
var import_react = require("react");
var import_utils = require("@pisell/utils");
var import_formatUtils = require("../utils/formatUtils");
var import_DetailContext = require("../DetailContext");
function useWalletCard({
  globalState,
  setGlobalState,
  walletContext,
  cardList,
  cardType,
  isDiscountCard = false,
  valueField = "balance",
  setupValue = "detail"
}) {
  const { state, dispatch } = walletContext;
  const { currentId, currentDetail } = globalState;
  const { openDetail, renderDetail } = (0, import_DetailContext.useDetail)();
  const platform = (0, import_react.useMemo)(() => (0, import_utils.isMobile)() ? "h5" : "pc", []);
  (0, import_react.useEffect)(() => {
    const total = (0, import_formatUtils.calculateTotalValue)(cardList, valueField);
    dispatch({
      type: "setState",
      payload: { total }
    });
  }, [cardList, dispatch, valueField]);
  (0, import_react.useEffect)(() => {
    if (currentId) {
      const detail = cardList.find((item) => item.id === currentId);
      if (detail) {
        dispatch({
          type: "setState",
          payload: { currentDetail: detail }
        });
      }
    }
  }, [currentId, cardList, dispatch]);
  const handleRowClick = (detail) => {
    setGlobalState({
      currentId: detail.id || "",
      currentDetail: detail,
      setup: platform === "h5" ? setupValue : void 0
      // 设置状态为detail
    });
    const detailToOpen = {
      ...detail,
      isDiscoundCard: isDiscountCard,
      showWalletBar: platform === "h5",
      // 添加显示WalletBar的标志
      onBack: () => {
        setGlobalState({ setup: "list" });
      }
    };
    openDetail(detailToOpen);
  };
  const renderCardDetail = () => {
    if (!(currentDetail == null ? void 0 : currentDetail.id)) return null;
    const detailToRender = {
      ...currentDetail,
      isDiscoundCard: isDiscountCard,
      showWalletBar: platform === "h5",
      // 添加显示WalletBar的标志
      onBack: () => {
        setGlobalState({ setup: "list" });
      }
    };
    return renderDetail(detailToRender);
  };
  const formatData = () => (0, import_formatUtils.formatDataToGroups)(cardList);
  const isEmpty = !(0, import_formatUtils.hasAvailableCards)(cardList);
  return {
    platform,
    currentId,
    currentDetail,
    isEmpty,
    state,
    dispatch,
    handleRowClick,
    renderCardDetail,
    formatData
  };
}
var useWalletCard_default = useWalletCard;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useWalletCard
});
