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/DiscountCard/index.tsx
var DiscountCard_exports = {};
__export(DiscountCard_exports, {
  default: () => DiscountCard_default
});
module.exports = __toCommonJS(DiscountCard_exports);
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_model = require("./model");
var import_DetailContext = require("../DetailContext");
var import_WalletCard = __toESM(require("../components/WalletCard"));
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 { Title } = import_materials.Typography;
var Amount = import_materials.PisellText.Amount;
var RechargeableCard = (0, import_model.Provider)((props) => {
  var _a, _b, _c;
  const { globalState, setGlobalState } = props;
  const { currentId, product_discount_card = [], currentDetail } = 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 platform = (0, import_react.useMemo)(() => (0, import_utils.isMobile)() ? "h5" : "pc", []);
  const { openDetail, renderDetail, closeDetail } = (0, import_DetailContext.useDetail)();
  const recordViewRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    if ((state == null ? void 0 : state.setup) !== "detail" && recordViewRef.current) {
      recordViewRef.current.closeDetailModal();
    }
  }, [state == null ? void 0 : state.setup]);
  (0, import_react.useEffect)(() => {
    if (globalState.setup && globalState.setup !== (state == null ? void 0 : state.setup)) {
      dispatch({
        type: "setState",
        payload: { setup: globalState.setup }
      });
    }
  }, [globalState.setup]);
  const handleBack = () => {
    if (recordViewRef.current) {
      recordViewRef.current.closeDetailModal();
    }
    closeDetail();
    dispatch({
      type: "setState",
      payload: { setup: "list" }
    });
    setGlobalState({
      setup: "list"
    });
  };
  const renderItem = (item) => {
    return /* @__PURE__ */ import_react.default.createElement(
      import_WalletCard.default,
      {
        item,
        currentId,
        isDiscountCard: true,
        onClick: () => {
          setGlobalState({
            currentId: item.id
          });
        }
      }
    );
  };
  (0, import_react.useEffect)(() => {
    if (currentId) {
      dispatch({
        type: "setState",
        payload: {
          currentDetail: product_discount_card.find(
            (item) => item.id === currentId
          )
        }
      });
    }
  }, [currentId]);
  (0, import_react.useEffect)(() => {
    const enabledCards = product_discount_card.filter(
      (item) => item.limit_status === "enable"
    );
    const total = enabledCards.reduce(
      (sum, item) => sum + Number(item.balance),
      0
    );
    dispatch({
      type: "setState",
      payload: {
        total
      }
    });
  }, [product_discount_card]);
  const isEmpty = !product_discount_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 = () => {
    const fileterArr = product_discount_card.filter(() => {
    });
    let available = {
      title: import_utils.locales.getText("page.wallet.available"),
      dataSource: product_discount_card.filter(
        (item) => item.limit_status === "enable"
      )
    };
    const unavailable = {
      title: import_utils.locales.getText("page.wallet.unavailable"),
      dataSource: product_discount_card.filter(
        (item) => item.limit_status === "disable"
      )
    };
    return [available, unavailable];
  };
  const detail = () => {
    if (!(currentDetail == null ? void 0 : currentDetail.id)) return null;
    const detailWithBar = {
      ...currentDetail,
      isDiscoundCard: true,
      showWalletBar: platform === "h5",
      // 添加显示WalletBar的标志
      onBack: handleBack
      // 添加返回处理函数
    };
    return renderDetail(detailWithBar);
  };
  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-discountCard-title" }, import_utils.locales.getText("page.wallet.discountCard")), /* @__PURE__ */ import_react.default.createElement(
    import_materials.RecordView,
    {
      ref: recordViewRef,
      leftSpan: 9,
      rightSpan: 15,
      gutter: 20,
      onRowClick: (currentDetail2) => {
        setGlobalState({
          currentId: currentDetail2.id || "",
          currentDetail: currentDetail2,
          setup: "detail"
          // 设置状态为detail
        });
        dispatch({
          type: "setState",
          payload: { setup: "detail" }
        });
        openDetail({
          ...currentDetail2,
          isDiscoundCard: true,
          showWalletBar: platform === "h5",
          // 添加显示WalletBar的标志
          onBack: handleBack
          // 添加返回处理函数
        });
      },
      pcDetailModalDisplay: platform === "h5" ? true : false,
      padDetailModalDisplay: true,
      mobilePadDetailModalDisplay: true,
      modalWrapStyle: {
        overflowY: "auto",
        top: 0,
        height: "100%",
        zIndex: 998,
        position: "fixed",
        left: 0,
        right: 0
      },
      split: false,
      detail: detail(),
      children: null,
      emptyButtons: [],
      doubleList: true,
      doubleListSource: formatData(),
      dataSource: product_discount_card,
      renderItem: (value) => renderItem(value),
      isShowClode: false
    }
  ));
});
var DiscountCard_default = RechargeableCard;
