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/OfflinePayment/index.tsx
var OfflinePayment_exports = {};
__export(OfflinePayment_exports, {
  default: () => OfflinePayment_default
});
module.exports = __toCommonJS(OfflinePayment_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 OfflinePayment = (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;
    try {
      paymentLogger.addLog({
        key: "OfflinePayment初始化开始",
        value: ""
      });
      const _item = payGroup == null ? void 0 : payGroup.otherPayment;
      const params = (0, import_payGroup.getPayGroupParamsFromStorage)(payGroup == null ? void 0 : payGroup.order_id, {
        order_id: payGroup == null ? void 0 : payGroup.order_id,
        payment_method: (_a2 = _item == null ? void 0 : _item.params) == null ? void 0 : _a2.payment_method
      });
      if (!params) {
        paymentLogger.addLog({
          key: "OfflinePayment获取支付参数失败",
          value: {
            title: `订单${payGroup == null ? void 0 : payGroup.order_id} 未找到存储的支付参数`,
            data: {
              payGroup
            }
          }
        });
        paymentLogger.sendLogs("OfflinePayment获取支付参数失败");
        return;
      }
      paymentLogger.addLog({
        key: "OfflinePayment获取支付参数成功",
        value: ""
      });
      paymentLogger.addLog({
        key: "OfflinePayment开始执行支付",
        value: {
          title: `订单${payGroup == null ? void 0 : payGroup.order_id} 开始执行线下支付`,
          data: {
            params,
            paymentMethod: (_b = _item == null ? void 0 : _item.params) == null ? void 0 : _b.payment_method
          }
        }
      });
      await (0, import_serve.offlinePayment)(params);
      paymentLogger.addLog({
        key: "OfflinePayment支付成功",
        value: ""
      });
      paymentLogger.sendLogs("OfflinePayment支付成功");
      state.payCallback({ key: "success" });
    } catch (err) {
      paymentLogger.addLog({
        key: "OfflinePayment处理错误",
        value: {
          title: `订单${payGroup == null ? void 0 : payGroup.order_id} OfflinePayment处理失败: ${(err == null ? void 0 : err.message) || "未知错误"}`,
          data: {
            payGroup
          }
        }
      });
      paymentLogger.sendLogs("OfflinePayment处理失败", err);
    }
  };
  (0, import_react.useImperativeHandle)(
    ref,
    () => ({
      init
    })
  );
  return null;
};
var OfflinePayment_default = (0, import_react.forwardRef)(OfflinePayment);
