require("../_virtual/_rolldown/runtime.js");
let react = require("react");
let _pisell_utils = require("@pisell/utils");
let ahooks = require("ahooks");
//#region src/hooks/usePaymentLogger.ts
/**
* @title: 支付日志记录器 Hook
* @description: 用于记录支付过程中的关键信息
* @param {UsePaymentLoggerOptions} options - 配置选项
* @return {object} 返回日志记录相关方法
* @Author: AI Assistant
*/
const usePaymentLogger = (options) => {
	const { orderId, step = "unknown" } = options;
	const logs = (0, react.useRef)([]);
	return {
		logs,
		addLog: (0, ahooks.useMemoizedFn)((logData) => {
			logs.current.push({
				key: logData.key,
				value: logData.value
			});
		}),
		sendLogs: (0, ahooks.useMemoizedFn)((title = "支付日志", err) => {
			const content = [{
				key: "title",
				value: title
			}, ...logs.current];
			if (err) content.push(...[
				{
					key: "错误信息",
					value: (err === null || err === void 0 ? void 0 : err.message) || "未知错误"
				},
				{
					key: "错误堆栈",
					value: (err === null || err === void 0 ? void 0 : err.stack) || "无堆栈信息"
				},
				{
					key: "错误类型",
					value: (err === null || err === void 0 ? void 0 : err.name) || "未知错误类型"
				}
			]);
			const formatLogs = content.map((item) => ({
				key: item.key,
				value: JSON.stringify(item.value)
			}));
			(0, _pisell_utils.sendWarningLog)({
				title: `h5支付step${step}:${orderId}`,
				content: formatLogs
			});
		})
	};
};
//#endregion
exports.default = usePaymentLogger;
