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/recharge/index.tsx
var recharge_exports = {};
__export(recharge_exports, {
  default: () => recharge_default
});
module.exports = __toCommonJS(recharge_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_serve = require("../../serve");
var import_index = require("./index.less");
var Recharge = ({
  platform = "pc",
  detailData,
  open,
  onClose
}) => {
  var _a, _b, _c, _d, _e, _f, _g;
  const [chargeItem, setChargeItem] = (0, import_react.useState)({});
  const context = (0, import_useEngineContext.default)();
  const { action, storage } = ((_a = context.appHelper) == null ? void 0 : _a.utils) || {};
  const dvaStore = (_e = (_d = (_c = (_b = context.appHelper) == null ? void 0 : _b.utils) == null ? void 0 : _c.getStore) == null ? void 0 : _d.call(_c)) == null ? void 0 : _e.getState();
  const shop = ((_g = (_f = dvaStore == null ? void 0 : dvaStore.core) == null ? void 0 : _f.core) == null ? void 0 : _g.shop) || {};
  const [loading, setLoading] = (0, import_react.useState)(false);
  (0, import_react.useEffect)(() => {
    if (detailData) {
      setChargeItem(((detailData == null ? void 0 : detailData.gift_option) || [])[0]);
    }
  }, [detailData]);
  const handleRecharge = async () => {
    var _a2;
    try {
      setLoading(true);
      const params = {
        voucher_id: (detailData == null ? void 0 : detailData.id) || "",
        product_id: (detailData == null ? void 0 : detailData.product_id) || "",
        product_variant_id: (chargeItem == null ? void 0 : chargeItem.variant_id) || "",
        quantity: 1,
        type: "virtual",
        platform: "h5",
        currency_code: {
          currency_code: (shop == null ? void 0 : shop.currency_code) || "",
          currency_symbol: (shop == null ? void 0 : shop.currency_symbol) || "",
          currency_format: (shop == null ? void 0 : shop.currency_format) || ""
        }
      };
      const data = await (0, import_serve.orderRechargeProduct)(params);
      if (data == null ? void 0 : data.order_id) {
        (_a2 = storage == null ? void 0 : storage.set) == null ? void 0 : _a2.call(storage, "orderId", data.order_id);
        action && action({
          type: "pisell1.payment",
          data,
          callback: () => {
          }
        });
      }
    } catch (error) {
      console.error(
        import_utils.locales.getText("wallet-pass-gallery.log.rechargeOrderFailed"),
        error
      );
    } finally {
      setLoading(false);
    }
  };
  return /* @__PURE__ */ import_react.default.createElement(
    import_antd.Drawer,
    {
      destroyOnClose: true,
      title: import_utils.locales.getText("wallet-pass-gallery.rechargeOptions"),
      open,
      zIndex: 999,
      onClose,
      width: 375,
      placement: platform === "pc" ? "right" : "bottom",
      footer: /* @__PURE__ */ import_react.default.createElement(
        import_antd.Button,
        {
          type: "primary",
          block: true,
          size: "large",
          onClick: handleRecharge,
          disabled: !(chargeItem == null ? void 0 : chargeItem.id),
          loading
        },
        import_utils.locales.getText("wallet-pass-gallery.recharge")
      )
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-wallet-pass-gallery_recharge" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-wallet-pass-gallery_recharge-options" }, ((detailData == null ? void 0 : detailData.gift_option) || []).map((item) => /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: item.id,
        className: "pisell-wallet-pass-gallery_recharge-card-item",
        onClick: () => setChargeItem(item)
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.PisellCard,
        {
          className: `pisell-card-item ${item.id === (chargeItem == null ? void 0 : chargeItem.id) ? "pisell-card-selected" : ""}`
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "card-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "card-content-left" }, /* @__PURE__ */ import_react.default.createElement("p", { className: "pisell-card-amount-item-name" }, item.name), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-card-amount-item-arrival" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-card-amount-item-label" }, import_utils.locales.getText(
          "wallet-pass-gallery.rechargeArrivalAmount"
        )), /* @__PURE__ */ import_react.default.createElement(
          import_materials.PisellText.Amount,
          {
            showCurrencySymbol: true,
            className: "highlight-amount",
            useThousandsSeparator: true,
            value: item.gift_price
          }
        ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "card-content-right" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pay-label" }, import_utils.locales.getText("wallet-pass-gallery.rechargePayAmount")), /* @__PURE__ */ import_react.default.createElement(
          import_materials.PisellText.Amount,
          {
            showCurrencySymbol: true,
            className: "pay-amount",
            useThousandsSeparator: true,
            value: item.price
          }
        )))
      )
    ))))
  );
};
var recharge_default = Recharge;
