const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
let decimal_js = require("decimal.js");
decimal_js = require_runtime.__toESM(decimal_js);
let _pisell_materials = require("@pisell/materials");
//#region src/components/checkout/components/WalletPassModule/utils.tsx
const Amount = _pisell_materials.PisellText.Amount;
const getAvailableMaxAmount = (data) => {
	if ((0, _pisell_utils.isNumber)(data._available_max_amount)) return data._available_max_amount;
	return data.tag !== "point_card" ? data.available_max_amount : data === null || data === void 0 ? void 0 : data.recommended_usage_amount;
};
const voucherTime = (data, key = "expire_date") => {
	const config = _pisell_materials.globalConfig.getConfig();
	if (data[key]) return (0, _pisell_utils.formatDate)(data[key], (config === null || config === void 0 ? void 0 : config.locale) === "en" ? "DD/MM/YYYY" : "YYYY-MM-DD");
	return _pisell_utils.locales.getText("pisell2.text.walletPassPermanent");
};
const getVoucherAvailableStatus = (item) => {
	return item.unified_available_status === 1 && ((0, _pisell_utils.isNumber)(item._unified_available_status) ? !!item._unified_available_status : true);
};
const formatMachineCodeServer2CardList = (data, selectId = [], otherProps = {}) => {
	return (data || []).map((item) => {
		var _item$unified_message, _item$product, _item$metadata, _item$custom_schedule;
		let disabled = false;
		if (item.unified_available_status === 0) disabled = true;
		else if ((0, _pisell_utils.isNumber)(item._unified_available_status)) disabled = !item._unified_available_status;
		return require_objectSpread2._objectSpread2({
			id: item.id,
			name: item.product_name,
			balance: item.balance_par_value,
			cardStatus: false,
			redeem: item.edit_current_amount !== void 0 ? item.edit_current_amount : getAvailableMaxAmount(item),
			maxRedeem: getAvailableMaxAmount(item),
			showRedeem: selectId.includes(item.id),
			showStoreName: false,
			showBalanceSymbol: item.tag !== "point_card",
			showActions: false,
			showDetail: false,
			showQrCode: false,
			showStatus: true,
			code: item.code,
			disabled,
			disabledReason: (0, _pisell_utils.isNumber)(item._unified_available_status) && item._unified_available_status !== 1 ? item.reason : (_item$unified_message = item.unified_messages) === null || _item$unified_message === void 0 ? void 0 : _item$unified_message.title,
			cover: (_item$product = item.product) === null || _item$product === void 0 ? void 0 : _item$product.cover,
			qrCode: item.code,
			validDate: voucherTime(item),
			originData: item,
			validDateBySchedule: ((_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.validity_type) === "custom_schedule_validity",
			scheduleList: ((_item$custom_schedule = item.custom_schedule_snapshot) === null || _item$custom_schedule === void 0 ? void 0 : _item$custom_schedule.data) || []
		}, otherProps);
	});
};
const formatDiscountWalletData = (data, selectId = []) => {
	return (data || []).map((item) => {
		var _item$product2, _item$custom_schedule2, _item$metadata3;
		let name = "";
		let storeName = "";
		if (item.tag === "product_discount_card" || item.tag === "discount_card") {
			var _item$metadata2;
			if ((item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.discount_card_type) === "fixed_amount") {
				const amountValue = (item === null || item === void 0 ? void 0 : item.savedAmount) ? item === null || item === void 0 ? void 0 : item.savedAmount : item.par_value;
				name = /* @__PURE__ */ react.default.createElement("span", null, _pisell_utils.locales.getText("pisell2.checkout.discount.fixed_amount"), " ", /* @__PURE__ */ react.default.createElement(Amount, {
					value: amountValue,
					showCurrencySymbol: true
				}));
			} else name = _pisell_utils.locales.getText("pisell2.checkout.discount.percentage.off")(item.par_value || item.discount.percent);
			storeName = item.product_name || item.format_title.auto;
		} else if (item.tag === "good_pass") {
			var _locales$getText;
			name = item.product_name;
			const left = Number(item.balance) || 0;
			storeName = (_locales$getText = _pisell_utils.locales.getText("pisell2.checkout.wallet-pass.good-pass.format")) === null || _locales$getText === void 0 ? void 0 : _locales$getText(left, 1);
		} else name = item.product_name;
		if (!name && item.isEditMode) {
			name = item.amount;
			storeName = item.format_title.auto;
		}
		return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
			id: item.id,
			name,
			storeName,
			balance: item.balance_par_value,
			showBalance: false,
			showStoreName: true,
			redeem: getAvailableMaxAmount(item),
			showRedeem: selectId.includes(item.id),
			showBalanceSymbol: item.tag !== "point_card",
			showActions: false,
			error: item.isDisabled,
			showDisabledReason: false,
			showDetail: false,
			showQrCode: false,
			code: item.code,
			disabled: item.isDisabled,
			showStatus: true,
			cardStatus: item.isEditMode ? "lastPayment" : item.isDisabled ? "conflict" : void 0,
			cover: (_item$product2 = item.product) === null || _item$product2 === void 0 ? void 0 : _item$product2.cover,
			qrCode: item.code,
			validDate: voucherTime(item, "expire_time"),
			originData: item,
			enableEditAmount: false,
			scheduleList: ((_item$custom_schedule2 = item.custom_schedule_snapshot) === null || _item$custom_schedule2 === void 0 ? void 0 : _item$custom_schedule2.data) || [],
			validDateBySchedule: ((_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.validity_type) === "custom_schedule_validity"
		});
	});
};
/**
* 根据WalletPassUsage配置，将传入的WalletPass面额转换为货币金额
*/
const getPointCardAmount = (walletPassValue, walletPassUsageUnit) => {
	if (!walletPassUsageUnit.points || !walletPassUsageUnit.price) return new decimal_js.default(walletPassValue).toFixed(2);
	return new decimal_js.default(walletPassValue).div(walletPassUsageUnit.points).mul(walletPassUsageUnit.price).toFixed(2, decimal_js.default.ROUND_DOWN);
};
const isSameContent = (arr1, arr2) => {
	return [...arr1].sort().join(",") === [...arr2].sort().join(",");
};
//#endregion
exports.formatDiscountWalletData = formatDiscountWalletData;
exports.formatMachineCodeServer2CardList = formatMachineCodeServer2CardList;
exports.getPointCardAmount = getPointCardAmount;
exports.getVoucherAvailableStatus = getVoucherAvailableStatus;
exports.isSameContent = isSameContent;
