const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_useCustomerGuard = require("./useCustomerGuard.js");
let react = require("react");
let decimal_js = require("decimal.js");
decimal_js = require_runtime.__toESM(decimal_js);
//#region src/components/checkout/hooks/useDepositStage.ts
function useDepositStage({ isDeposit, depositAmount, paymentItems = [] }) {
	return (0, react.useMemo)(() => {
		const depositTarget = new decimal_js.default(depositAmount || 0);
		const depositPaid = paymentItems.reduce((sum, payment) => {
			if ((payment === null || payment === void 0 ? void 0 : payment.status) === "voided") return sum;
			if ((payment === null || payment === void 0 ? void 0 : payment.order_payment_type) !== "deposit" && (payment === null || payment === void 0 ? void 0 : payment.type) !== "deposit") return sum;
			return sum.plus(payment.amount || 0).minus(payment.rounding_amount || 0);
		}, new decimal_js.default(0));
		const hasNormalPayment = paymentItems.some((payment) => {
			if ((payment === null || payment === void 0 ? void 0 : payment.status) === "voided") return false;
			if (require_useCustomerGuard.isWalletPassPayment(payment)) return false;
			return (payment === null || payment === void 0 ? void 0 : payment.order_payment_type) !== "deposit" && (payment === null || payment === void 0 ? void 0 : payment.type) !== "deposit";
		});
		const isDepositFullyPaid = depositTarget.gt(0) && depositPaid.gte(depositTarget);
		const canUseDepositPayment = !!isDeposit && !hasNormalPayment && !isDepositFullyPaid;
		return {
			depositTarget: depositTarget.toFixed(2),
			depositPaid: depositPaid.toFixed(2),
			isDepositFullyPaid,
			canUseDepositPayment,
			shouldUseNormalPayment: !canUseDepositPayment
		};
	}, [
		depositAmount,
		isDeposit,
		paymentItems
	]);
}
//#endregion
exports.useDepositStage = useDepositStage;
