import { _asyncToGenerator } from "../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import { ToBPayContext } from "./context.js";
import { handlePayMethodList } from "./utils.js";
import { useOSPayment } from "./hooks.js";
import React, { useState } from "react";
//#region src/components/pay/toB/store/provider.tsx
const ToBPayProvider = ({ children }) => {
	const osPayment = useOSPayment();
	const [order, setOrder] = useState({});
	const [orderInfo, setOrderInfo] = useState({});
	const [payMethodGroupList, setPayMethodGroupList] = useState([]);
	const contextValue = {
		order,
		setOrder,
		orderInfo,
		setOrderInfo,
		payMethodGroupList,
		setPayMethodGroupList,
		getPayMethodList: function() {
			var _ref = _asyncToGenerator(function* () {
				if (!osPayment) {
					setPayMethodGroupList([]);
					console.error("osPayment is not initialized");
					return;
				}
				try {
					const payMethodList = yield osPayment.getPayMethodListAsync();
					console.log("payMethodList", payMethodList);
					setPayMethodGroupList(handlePayMethodList(payMethodList));
				} catch (error) {
					console.error(error);
				}
			});
			return function getPayMethodList() {
				return _ref.apply(this, arguments);
			};
		}()
	};
	return /* @__PURE__ */ React.createElement(ToBPayContext.Provider, { value: contextValue }, children);
};
//#endregion
export { ToBPayProvider };
