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_index = require("../../../../utils/index.js");
const require_status = require("./status.js");
const require_utils = require("./utils.js");
let _pisell_utils = require("@pisell/utils");
//#region src/components/pay/toC/PaymentList/serve.ts
/**
* @title: 获取支付列表
* @description: 
* @param {any} values
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-08-16 10:57
*/
const getPaymentList = function() {
	var _ref = require_asyncToGenerator._asyncToGenerator(function* (values) {
		let { data = [] } = yield require_index.request.getRequest().get("/h5/pay/order/payments", values);
		return filterPaymentList(data);
	});
	return function getPaymentList(_x) {
		return _ref.apply(this, arguments);
	};
}();
const sortArr = [
	"mw.google",
	"mw.apple",
	"mw.credit_card",
	"stripe",
	"pisell.bank_deposit",
	"superpay.alipay.h5",
	"superpay.wechat.h5",
	"pisell.offline_payment",
	"pisell.other.cashmanual",
	"pisell.custom_payment"
];
/**
* @title: 过滤支付列表
* @description: 
* @param {any} list
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-08-16 10:57
*/
const filterPaymentList = (list, platform = "h5", isApp, amount) => {
	let paymentList = [...list];
	let _paymentKeys = [...require_status.paymentKeys];
	const walletPass = paymentList.find((d) => d.service === "pisell.wallet_pass");
	let arr = [];
	if (!(0, _pisell_utils.isWx)() && !isApp) arr = arr.concat(["globepay.wechat.jsapi", "superpay.wechat.h5"]);
	if (platform === "h5") arr = arr.concat(["globepay.wechat.qrcode", "globepay.alipay.qrcode"]);
	if (!(0, _pisell_utils.isIOS)() && !(0, _pisell_utils.isSafari)()) arr = arr.concat(["mw.apple"]);
	if ((0, _pisell_utils.isIOS)() && isApp) arr = arr.concat(["mw.google"]);
	_paymentKeys = _paymentKeys.filter((d) => !arr.includes(d));
	paymentList = paymentList.filter((d) => _paymentKeys.includes(d.service));
	if (paymentList.length === 0) return {
		message: "该店铺暂未启用支付功能",
		status: "error",
		paymentList: [],
		walletPass
	};
	paymentList = paymentList.sort((a, b) => {
		return sortArr.indexOf(a.service) - sortArr.indexOf(b.service);
	});
	paymentList = paymentList.map((d) => {
		let _item = require_status.paymentTypes.find((t) => t.service === d.service);
		let service = d.service;
		if (require_status.isCustomPayment(d.service)) service = service + "|" + d.params.custom_payment_id;
		if (service === "mw.credit_card") {
			d.surcharge = require_utils.formatCreditCardSurchargeText(d === null || d === void 0 ? void 0 : d.surcharge_config, d === null || d === void 0 ? void 0 : d.surcharge_text);
			d.surcharge_config_result = require_utils.formatCreditCardSurchargeList(d, amount !== null && amount !== void 0 ? amount : 0);
		}
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, d), {}, {
			service,
			title: d.name,
			url: _item === null || _item === void 0 ? void 0 : _item.url,
			imageStyle: _item === null || _item === void 0 ? void 0 : _item.imageStyle
		});
	});
	return {
		message: "",
		status: "ready",
		paymentList,
		walletPass
	};
};
//#endregion
exports.filterPaymentList = filterPaymentList;
exports.getPaymentList = getPaymentList;
