import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import useLogger from "../../../hooks/useLogger.js";
import { useMemo } from "react";
import { useMemoizedFn } from "ahooks";
//#region src/components/checkout/hooks/usePaymentLogger.ts
const usePaymentLogger = () => {
	var _context$appHelper, _checkout$getCurrentO;
	const context = useEngineContext();
	const { pisellos } = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	const logger = useLogger();
	const checkout = useMemo(() => {
		try {
			return (pisellos === null || pisellos === void 0 ? void 0 : pisellos.getModule("checkout")) || null;
		} catch (error) {
			console.warn("Failed to get checkout module:", error);
			return null;
		}
	}, [pisellos]);
	const orderInfo = checkout === null || checkout === void 0 || (_checkout$getCurrentO = checkout.getCurrentOrderInfo) === null || _checkout$getCurrentO === void 0 ? void 0 : _checkout$getCurrentO.call(checkout);
	const addLog = useMemoizedFn((data) => {
		try {
			var _logger$addLog2;
			if (!checkout || !orderInfo) {
				var _logger$addLog;
				logger === null || logger === void 0 || (_logger$addLog = logger.addLog) === null || _logger$addLog === void 0 || _logger$addLog.call(logger, data);
				return;
			}
			logger === null || logger === void 0 || (_logger$addLog2 = logger.addLog) === null || _logger$addLog2 === void 0 || _logger$addLog2.call(logger, _objectSpread2(_objectSpread2({}, data), {}, {
				metadata: _objectSpread2(_objectSpread2({}, data === null || data === void 0 ? void 0 : data.metadata), {}, { orderInfo }),
				title: `${orderInfo.orderId}-${data.title}`
			}));
		} catch (error) {
			var _logger$addLog3;
			console.error("Failed to add payment log:", error);
			logger === null || logger === void 0 || (_logger$addLog3 = logger.addLog) === null || _logger$addLog3 === void 0 || _logger$addLog3.call(logger, data);
		}
	});
	return _objectSpread2(_objectSpread2({}, logger), {}, { addLog });
};
//#endregion
export { usePaymentLogger as default };
