require("../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_payGroup = require("../../payGroup.js");
const require_model = require("../../model.js");
const require_usePaymentLogger = require("../../../../../hooks/usePaymentLogger.js");
const require_serve = require("./serve.js");
let react = require("react");
require("./index.less");
//#region src/components/pay/toC/PaymentMethods/CashManual/index.tsx
/**
* @title: cash 支付
* @description:
* @param {CashManualProps} props
* @param {React} ref
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-08-16 11:00
*/
const CashManual = (props, ref) => {
	var _state$payGroup;
	const { state } = (0, react.useContext)(require_model.Context);
	const paymentLogger = require_usePaymentLogger.default({
		orderId: ((_state$payGroup = state.payGroup) === null || _state$payGroup === void 0 ? void 0 : _state$payGroup.order_id) || "unknown",
		step: "2"
	});
	/**
	* @title: 初始化
	* @description:
	* @param {any} param1
	* @return {*}
	* @Author: zhiwei.Wang
	* @Date: 2024-08-16 11:00
	*/
	const init = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* ({ payGroup }) {
			var _state$payGroup2, _state$payGroup3;
			paymentLogger.addLog({
				key: "CashManual初始化开始",
				value: ""
			});
			let current = ((_state$payGroup2 = state.payGroup) === null || _state$payGroup2 === void 0 ? void 0 : _state$payGroup2.otherPayment) || {};
			const orderId = (payGroup === null || payGroup === void 0 ? void 0 : payGroup.order_id) || ((_state$payGroup3 = state.payGroup) === null || _state$payGroup3 === void 0 ? void 0 : _state$payGroup3.order_id);
			const values = require_payGroup.getPayGroupParamsFromStorage(orderId);
			if (!values) {
				paymentLogger.addLog({
					key: "CashManual获取支付参数失败",
					value: {
						title: `订单${orderId} 未找到存储的支付参数`,
						data: { payGroup }
					}
				});
				paymentLogger.sendLogs("CashManual获取支付参数失败");
				return;
			}
			paymentLogger.addLog({
				key: "CashManual获取支付参数成功",
				value: ""
			});
			try {
				paymentLogger.addLog({
					key: "CashManual开始支付API调用",
					value: ""
				});
				yield require_serve.customPaymentApi(orderId, require_objectSpread2._objectSpread2({ params: current.params }, values));
				paymentLogger.addLog({
					key: "CashManual支付API调用成功",
					value: ""
				});
				paymentLogger.sendLogs("CashManual支付成功");
				state.payCallback({ key: "success" });
			} catch (err) {
				paymentLogger.addLog({
					key: "CashManual支付错误",
					value: {
						title: `订单${orderId} CashManual支付失败: ${(err === null || err === void 0 ? void 0 : err.message) || "未知错误"}`,
						data: {
							payGroup,
							current,
							values
						}
					}
				});
				paymentLogger.sendLogs("CashManual支付失败", err);
			}
		});
		return function init(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	(0, react.useImperativeHandle)(ref, () => ({ init }));
	return null;
};
var CashManual_default = (0, react.forwardRef)(CashManual);
//#endregion
exports.default = CashManual_default;
