const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
//#region src/components/checkout/utils.ts
const getShopWalletPassId = function() {
	var _ref = require_asyncToGenerator._asyncToGenerator(function* (interaction) {
		try {
			var _interaction$utils, _interaction$utils$as;
			return yield interaction === null || interaction === void 0 || (_interaction$utils = interaction.utils) === null || _interaction$utils === void 0 || (_interaction$utils$as = _interaction$utils.asyncDataManager) === null || _interaction$utils$as === void 0 ? void 0 : _interaction$utils$as.call(_interaction$utils, {
				module: "get",
				key: "till_id"
			});
		} catch (error) {
			console.warn("Failed to get till_id from asyncDataManager:", error);
			return null;
		}
	});
	return function getShopWalletPassId(_x) {
		return _ref.apply(this, arguments);
	};
}();
/**
* 工具函数：将支付方式 ID 转换为数字类型
* @param id 支付方式 ID
* @returns 转换后的数字 ID，如果转换失败则返回 null
*/
const convertPaymentMethodId = (id) => {
	if (id === void 0 || id === null) return null;
	const numericId = Number(id);
	return isNaN(numericId) ? null : numericId;
};
/**
* 工具函数：验证 terminal 支付方式列表的有效性
* @param terminalList terminal 返回的支付方式列表
* @returns 是否为有效的列表
*/
const isValidTerminalPaymentMethodList = (terminalList) => {
	return !!(terminalList && Array.isArray(terminalList) && terminalList.length > 0);
};
const reorderPaymentMethodList = function() {
	var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (paymentMethodList, interaction) {
		try {
			var _interaction$utils2, _interaction$utils2$a;
			const terminalPaymentMethodList = yield interaction === null || interaction === void 0 || (_interaction$utils2 = interaction.utils) === null || _interaction$utils2 === void 0 || (_interaction$utils2$a = _interaction$utils2.asyncDataManager) === null || _interaction$utils2$a === void 0 ? void 0 : _interaction$utils2$a.call(_interaction$utils2, {
				module: "get",
				key: "payment_method_list"
			});
			console.log(terminalPaymentMethodList, "terminalPaymentMethodList");
			if (!isValidTerminalPaymentMethodList(terminalPaymentMethodList)) {
				console.info("No terminal payment method list found, using original order");
				return paymentMethodList;
			}
			const paymentMethodMap = /* @__PURE__ */ new Map();
			const orderedPaymentMethods = [];
			paymentMethodList.forEach((method) => {
				const numericId = convertPaymentMethodId(method === null || method === void 0 ? void 0 : method.id);
				if (numericId !== null) paymentMethodMap.set(numericId, method);
				else console.warn("Payment method has invalid or missing id", {
					id: method === null || method === void 0 ? void 0 : method.id,
					method
				});
			});
			terminalPaymentMethodList.forEach((item) => {
				if (!(item === null || item === void 0 ? void 0 : item.hidden)) {
					const paymentMethod = paymentMethodMap.get(Number(item.id));
					if (paymentMethod) orderedPaymentMethods.push(paymentMethod);
				}
			});
			return orderedPaymentMethods;
		} catch (error) {
			console.error("Failed to reorder payment method list:", error);
			return paymentMethodList || [];
		}
	});
	return function reorderPaymentMethodList(_x2, _x3) {
		return _ref2.apply(this, arguments);
	};
}();
//#endregion
exports.getShopWalletPassId = getShopWalletPassId;
exports.reorderPaymentMethodList = reorderPaymentMethodList;
