import { isWalletPassPayment } from "./useCustomerGuard.js";
import { useMemo } from "react";
import Decimal from "decimal.js";
//#region src/components/checkout/hooks/useDepositStage.ts
function useDepositStage({ isDeposit, depositAmount, paymentItems = [] }) {
	return useMemo(() => {
		const depositTarget = new Decimal(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(0));
		const hasNormalPayment = paymentItems.some((payment) => {
			if ((payment === null || payment === void 0 ? void 0 : payment.status) === "voided") return false;
			if (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
export { useDepositStage };
