const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_asyncToGenerator = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../../hooks/useEngineContext.js");
const require_serve = require("../../serve.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
require("./index.less");
//#region src/plus/walletPassGallery/components/recharge/index.tsx
const Recharge = ({ platform = "pc", detailData, open, onClose }) => {
	var _context$appHelper, _context$appHelper2, _context$appHelper2$g, _dvaStore$core;
	const [chargeItem, setChargeItem] = (0, react.useState)({});
	const context = require_useEngineContext.default();
	const { action, storage } = ((_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	const dvaStore = (_context$appHelper2 = context.appHelper) === null || _context$appHelper2 === void 0 || (_context$appHelper2 = _context$appHelper2.utils) === null || _context$appHelper2 === void 0 || (_context$appHelper2$g = _context$appHelper2.getStore) === null || _context$appHelper2$g === void 0 || (_context$appHelper2$g = _context$appHelper2$g.call(_context$appHelper2)) === null || _context$appHelper2$g === void 0 ? void 0 : _context$appHelper2$g.getState();
	const shop = (dvaStore === null || dvaStore === void 0 || (_dvaStore$core = dvaStore.core) === null || _dvaStore$core === void 0 || (_dvaStore$core = _dvaStore$core.core) === null || _dvaStore$core === void 0 ? void 0 : _dvaStore$core.shop) || {};
	const [loading, setLoading] = (0, react.useState)(false);
	(0, react.useEffect)(() => {
		if (detailData) setChargeItem(((detailData === null || detailData === void 0 ? void 0 : detailData.gift_option) || [])[0]);
	}, [detailData]);
	const handleRecharge = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* () {
			try {
				setLoading(true);
				const data = yield require_serve.orderRechargeProduct({
					voucher_id: (detailData === null || detailData === void 0 ? void 0 : detailData.id) || "",
					product_id: (detailData === null || detailData === void 0 ? void 0 : detailData.product_id) || "",
					product_variant_id: (chargeItem === null || chargeItem === void 0 ? void 0 : chargeItem.variant_id) || "",
					quantity: 1,
					type: "virtual",
					platform: "h5",
					currency_code: {
						currency_code: (shop === null || shop === void 0 ? void 0 : shop.currency_code) || "",
						currency_symbol: (shop === null || shop === void 0 ? void 0 : shop.currency_symbol) || "",
						currency_format: (shop === null || shop === void 0 ? void 0 : shop.currency_format) || ""
					}
				});
				if (data === null || data === void 0 ? void 0 : data.order_id) {
					var _storage$set;
					storage === null || storage === void 0 || (_storage$set = storage.set) === null || _storage$set === void 0 || _storage$set.call(storage, "orderId", data.order_id);
					action && action({
						type: "pisell1.payment",
						data,
						callback: () => {}
					});
				}
			} catch (error) {
				console.error(_pisell_utils.locales.getText("wallet-pass-gallery.log.rechargeOrderFailed"), error);
			} finally {
				setLoading(false);
			}
		});
		return function handleRecharge() {
			return _ref.apply(this, arguments);
		};
	}();
	return /* @__PURE__ */ react.default.createElement(antd.Drawer, {
		destroyOnClose: true,
		title: _pisell_utils.locales.getText("wallet-pass-gallery.rechargeOptions"),
		open,
		zIndex: 999,
		onClose,
		width: 375,
		placement: platform === "pc" ? "right" : "bottom",
		footer: /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "primary",
			block: true,
			size: "large",
			onClick: handleRecharge,
			disabled: !(chargeItem === null || chargeItem === void 0 ? void 0 : chargeItem.id),
			loading
		}, _pisell_utils.locales.getText("wallet-pass-gallery.recharge"))
	}, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-wallet-pass-gallery_recharge" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-wallet-pass-gallery_recharge-options" }, ((detailData === null || detailData === void 0 ? void 0 : detailData.gift_option) || []).map((item) => /* @__PURE__ */ react.default.createElement("div", {
		key: item.id,
		className: "pisell-wallet-pass-gallery_recharge-card-item",
		onClick: () => setChargeItem(item)
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellCard, { className: `pisell-card-item ${item.id === (chargeItem === null || chargeItem === void 0 ? void 0 : chargeItem.id) ? "pisell-card-selected" : ""}` }, /* @__PURE__ */ react.default.createElement("div", { className: "card-content" }, /* @__PURE__ */ react.default.createElement("div", { className: "card-content-left" }, /* @__PURE__ */ react.default.createElement("p", { className: "pisell-card-amount-item-name" }, item.name), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-card-amount-item-arrival" }, /* @__PURE__ */ react.default.createElement("span", { className: "pisell-card-amount-item-label" }, _pisell_utils.locales.getText("wallet-pass-gallery.rechargeArrivalAmount")), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellText.Amount, {
		showCurrencySymbol: true,
		className: "highlight-amount",
		useThousandsSeparator: true,
		value: item.gift_price
	}))), /* @__PURE__ */ react.default.createElement("div", { className: "card-content-right" }, /* @__PURE__ */ react.default.createElement("span", { className: "pay-label" }, _pisell_utils.locales.getText("wallet-pass-gallery.rechargePayAmount")), /* @__PURE__ */ react.default.createElement(_pisell_materials.PisellText.Amount, {
		showCurrencySymbol: true,
		className: "pay-amount",
		useThousandsSeparator: true,
		value: item.price
	})))))))));
};
//#endregion
exports.default = Recharge;
