import { _objectSpread2 } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _objectWithoutProperties } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js";
import useLogger from "../../../../hooks/useLogger.js";
import EFTPOS_default from "../components/EFTPOS/index.js";
import MX51_default from "../components/MX51/index.js";
import React, { forwardRef, useImperativeHandle, useRef } from "react";
//#region src/components/pay/toB/paymentMethods/index.tsx
const _excluded = ["callback"];
const PaymentMethods = (props, ref) => {
	const eftposRef = useRef(null);
	const mx51Ref = useRef(null);
	const logger = useLogger();
	const onPay = (type, params) => {
		const { callback } = params, otherParams = _objectWithoutProperties(params, _excluded);
		console.log("onPay_params>>>>", type, params);
		logger === null || logger === void 0 || logger.addLog({
			type: "info",
			title: "ToB_PaymentMethods_onPay 开始调用",
			metadata: {
				type,
				params
			}
		});
		if (type === "eftpos") {
			var _eftposRef$current, _eftposRef$current$op;
			(_eftposRef$current = eftposRef.current) === null || _eftposRef$current === void 0 || (_eftposRef$current$op = _eftposRef$current.open) === null || _eftposRef$current$op === void 0 || _eftposRef$current$op.call(_eftposRef$current, _objectSpread2(_objectSpread2({}, otherParams), {}, { payCallback: (res) => _eftpcallback(res, callback) }));
		} else if (type === "mx51") {
			var _mx51Ref$current, _mx51Ref$current$open;
			(_mx51Ref$current = mx51Ref.current) === null || _mx51Ref$current === void 0 || (_mx51Ref$current$open = _mx51Ref$current.open) === null || _mx51Ref$current$open === void 0 || _mx51Ref$current$open.call(_mx51Ref$current, _objectSpread2(_objectSpread2({}, otherParams), {}, { payCallback: (res) => _mx51callback(res, callback) }));
		}
	};
	const _eftpcallback = (res, callback) => {
		const params = {
			status: res.status,
			data: res.params
		};
		logger === null || logger === void 0 || logger.addLog({
			type: "info",
			title: "ToB_PaymentMethods_eftpos_callback",
			metadata: {
				res,
				params
			}
		});
		callback(params);
	};
	const _mx51callback = (res, callback) => {
		const params = {
			status: res.result ? "success" : "fail",
			data: {
				amount: res.amount,
				surcharge: res.surcharge,
				uniquePaymentNumber: res.uniquePaymentNumber
			},
			msg: res.msg
		};
		logger === null || logger === void 0 || logger.addLog({
			type: "info",
			title: "ToB_PaymentMethods_mx51_callback",
			metadata: {
				res,
				params
			}
		});
		callback(params);
	};
	useImperativeHandle(ref, () => ({ onPay }));
	return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(EFTPOS_default, {
		ref: eftposRef,
		dynamicMaxHeight: props === null || props === void 0 ? void 0 : props.dynamicMaxHeight,
		isWebPos: props === null || props === void 0 ? void 0 : props.isWebPos
	}), /* @__PURE__ */ React.createElement(MX51_default, { ref: mx51Ref }));
};
var paymentMethods_default = forwardRef(PaymentMethods);
//#endregion
export { paymentMethods_default as default };
