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/pay/toC/PaymentMethods/StripePay/index.tsx
var StripePay_exports = {};
__export(StripePay_exports, {
  default: () => StripePay_default
});
module.exports = __toCommonJS(StripePay_exports);
var import_react = require("react");
var import_model = require("../../model");
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var import_usePaymentLogger = __toESM(require("../../../../../hooks/usePaymentLogger"));
var import_index = require("./index.less");
var StripePay = (props, ref) => {
  var _a;
  const { state } = (0, import_react.useContext)(import_model.Context);
  const context = (0, import_useEngineContext.default)();
  const paymentLogger = (0, import_usePaymentLogger.default)({
    orderId: ((_a = state == null ? void 0 : state.payGroup) == null ? void 0 : _a.order_id) || "unknown",
    step: "2"
  });
  const init = async ({ payGroup }) => {
    var _a2, _b;
    paymentLogger.addLog({
      key: "StripePay初始化开始",
      value: ""
    });
    try {
      let _item = payGroup == null ? void 0 : payGroup.otherPayment;
      const platform = ((_b = (_a2 = context.appHelper) == null ? void 0 : _a2.constants) == null ? void 0 : _b.platform) || "h5";
      paymentLogger.addLog({
        key: "StripePay平台检测",
        value: {
          platform,
          paymentItem: _item
        }
      });
      if (platform === "pc") {
        paymentLogger.addLog({
          key: "StripePay PC端回调准备",
          value: {
            service: _item.service,
            orderId: payGroup.order_id,
            paymentMethod: _item.title
          }
        });
        state.payCallback({
          key: _item.service,
          data: {
            order_id: payGroup.order_id,
            payment_method: _item.title
          }
        });
        paymentLogger.sendLogs("StripePay PC端回调成功");
        return;
      }
      const redirectUrl = `/pay/stripe?order_id=${payGroup.order_id}&payment_method=${encodeURIComponent(_item.title)}`;
      paymentLogger.addLog({
        key: "StripePay H5端跳转准备",
        value: {
          redirectUrl
        }
      });
      window.location.href = redirectUrl;
      paymentLogger.sendLogs("StripePay H5端跳转成功");
    } catch (err) {
      paymentLogger.addLog({
        key: "StripePay处理错误",
        value: {
          title: `订单${payGroup == null ? void 0 : payGroup.order_id} StripePay处理失败: ${(err == null ? void 0 : err.message) || "未知错误"}`,
          data: {
            payGroup
          }
        }
      });
      paymentLogger.sendLogs("StripePay处理失败", err);
    }
  };
  (0, import_react.useImperativeHandle)(
    ref,
    () => ({
      init
    })
  );
  return null;
};
var StripePay_default = (0, import_react.forwardRef)(StripePay);
