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/CustomPayment/index.tsx
var CustomPayment_exports = {};
__export(CustomPayment_exports, {
  default: () => CustomPayment_default
});
module.exports = __toCommonJS(CustomPayment_exports);
var import_react = require("react");
var import_serve = require("./serve");
var import_model = require("../../model");
var import_payGroup = require("../../payGroup");
var import_usePaymentLogger = __toESM(require("../../../../../hooks/usePaymentLogger"));
var import_index = require("./index.less");
var CustomPayment = (props, ref) => {
  var _a;
  const { state } = (0, import_react.useContext)(import_model.Context);
  const paymentLogger = (0, import_usePaymentLogger.default)({
    orderId: ((_a = state.payGroup) == null ? void 0 : _a.order_id) || "unknown",
    step: "2"
  });
  const init = async ({ payGroup }) => {
    var _a2, _b;
    paymentLogger.addLog({
      key: "CustomPayment初始化开始",
      value: ""
    });
    let current = ((_a2 = state.payGroup) == null ? void 0 : _a2.otherPayment) || {};
    const orderId = (payGroup == null ? void 0 : payGroup.order_id) || ((_b = state.payGroup) == null ? void 0 : _b.order_id);
    const values = (0, import_payGroup.getPayGroupParamsFromStorage)(orderId);
    if (!values) {
      paymentLogger.addLog({
        key: "CustomPayment获取支付参数失败",
        value: {
          title: `订单${orderId} 未找到存储的支付参数`,
          data: {
            payGroup
          }
        }
      });
      paymentLogger.sendLogs("CustomPayment获取支付参数失败");
      return;
    }
    paymentLogger.addLog({
      key: "CustomPayment获取支付参数成功",
      value: ""
    });
    try {
      paymentLogger.addLog({
        key: "CustomPayment开始支付API调用",
        value: ""
      });
      await (0, import_serve.customPaymentApi)(orderId, {
        params: current.params,
        ...values
      });
      paymentLogger.addLog({
        key: "CustomPayment支付API调用成功",
        value: ""
      });
      paymentLogger.sendLogs("CustomPayment支付成功");
      state.payCallback({
        key: "success"
      });
    } catch (err) {
      paymentLogger.addLog({
        key: "CustomPayment支付错误",
        value: {
          title: `订单${orderId} CustomPayment支付失败: ${(err == null ? void 0 : err.message) || "未知错误"}`,
          data: {
            payGroup,
            current,
            values
          }
        }
      });
      paymentLogger.sendLogs("CustomPayment支付失败", err);
    }
  };
  (0, import_react.useImperativeHandle)(
    ref,
    () => ({
      init
    })
  );
  return null;
};
var CustomPayment_default = (0, import_react.forwardRef)(CustomPayment);
