import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { request } from "../../../utils/index.js";
import { paymentKeys } from "./status.js";
import { isIOS, isSafari, isWx } from "@pisell/utils";
(function() {
	var _ref = _asyncToGenerator(function* (values) {
		let paymentList = [];
		let { data } = yield request.getRequest().get("/h5/pay/order/payments", values);
		paymentList = (data || []).filter((d) => paymentKeys.includes(d.service));
		let arr = [];
		if (isWx()) arr = arr.concat(["mw.google"]);
		if (!isWx()) arr = arr.concat(["globepay.wechat.jsapi", "superpay.wechat.h5"]);
		if (!isIOS() && !isSafari()) arr = arr.concat(["mw.apple"]);
		paymentList = paymentList.filter((d) => !arr.includes(d.service));
		if (paymentList.length === 0) return {
			message: "component.Payment.toast.the-payment-function-is-not-enabled",
			status: "error"
		};
		return {
			message: "",
			status: "ready",
			paymentList
		};
	});
	return function getPaymentList(_x) {
		return _ref.apply(this, arguments);
	};
})();
/**
* @title: 聚合接口, 根据订单 返回支付列表和钱包
* @description:
* @param {object} values
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-08-15 11:52
*/
const getPaymentsAndWalletPass = function() {
	var _ref2 = _asyncToGenerator(function* (values, apiPrefix) {
		let { data } = yield request.getRequest().get(`/${apiPrefix || "h5"}/pay/order/payments-and-walletpass`, values);
		if (values === null || values === void 0 ? void 0 : values.filter_wallet_pass_flag) return _objectSpread2(_objectSpread2({}, data), {}, { walletPass: null });
		const walletPass = (data.payment_list || []).find((d) => d.service === "pisell.wallet_pass");
		return _objectSpread2(_objectSpread2({}, data), {}, { walletPass });
	});
	return function getPaymentsAndWalletPass(_x2, _x3) {
		return _ref2.apply(this, arguments);
	};
}();
/**
* @title: 初始化交易组
* @description:
* @param {object} values
* @return {*}
* @Author: zhiwei.Wang
* @Date: 2024-08-16 10:42
*/
const getPaymentInit = function() {
	var _ref3 = _asyncToGenerator(function* (values) {
		let { data } = yield request.getRequest().post("/h5/pay/payment/init", values);
		return data;
	});
	return function getPaymentInit(_x4) {
		return _ref3.apply(this, arguments);
	};
}();
/**
* @title: 获取钱包名称和弹窗状态
* @description:
* @param {object} values
* @return {*}
* @Author: shengjie.zuo
* @member: 马天宇
* @Date: 2025-02-21 10:42
*/
const getWalletNameAndPopupStatus = function() {
	var _ref4 = _asyncToGenerator(function* (values) {
		const { data } = yield request.getRequest().get("/h5/wallet/setting", values);
		return data;
	});
	return function getWalletNameAndPopupStatus(_x5) {
		return _ref4.apply(this, arguments);
	};
}();
/**
* @title: 获取支付结果
* @description: 获取支付结果
*/
const getPaymentResult = (values) => request.getRequest().get(`/h5/pay/order/payment/result`, values);
/**
* @title: 查询订单基础信息和订单商品信息
* @description: 查询订单基础信息和订单商品信息
* @param {string} order_id
* @return {*}
*/
const getOrderBasicDetail = function() {
	var _ref5 = _asyncToGenerator(function* (order_id) {
		const { data } = yield request.getRequest().get(`/h5/order/order/${order_id}/basic-detail`, {});
		return data;
	});
	return function getOrderBasicDetail(_x6) {
		return _ref5.apply(this, arguments);
	};
}();
/**
* @title: 检测订单是否有正在处理中的交易
* @param {object} values - { order_id: string }
* @return {Promise<{ has_pending: boolean }>}
*/
const checkPendingPayment = function() {
	var _ref6 = _asyncToGenerator(function* (values) {
		var _data$payment_handlin;
		const { data } = yield request.getRequest().post(`/h5/pay/payment/check`, values);
		if ((data === null || data === void 0 ? void 0 : data.payment_handling_list) && (data === null || data === void 0 || (_data$payment_handlin = data.payment_handling_list) === null || _data$payment_handlin === void 0 ? void 0 : _data$payment_handlin.length) > 0) return { has_pending: true };
		return { has_pending: false };
	});
	return function checkPendingPayment(_x7) {
		return _ref6.apply(this, arguments);
	};
}();
/**
* 调用服务端暂存接口，写入 payGroup 等数据。
*/
const postCoreStash = function() {
	var _ref7 = _asyncToGenerator(function* (params) {
		var _params$ttl;
		const body = {
			token: params.token,
			data: params.data,
			ttl: (_params$ttl = params.ttl) !== null && _params$ttl !== void 0 ? _params$ttl : 86400
		};
		yield request.getRequest().post("/h5/core/stash", body, {});
	});
	return function postCoreStash(_x8) {
		return _ref7.apply(this, arguments);
	};
}();
//#endregion
export { checkPendingPayment, getOrderBasicDetail, getPaymentInit, getPaymentResult, getPaymentsAndWalletPass, getWalletNameAndPopupStatus, postCoreStash };
