var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/checkout/hooks/useDepositStage.ts
var useDepositStage_exports = {};
__export(useDepositStage_exports, {
  useDepositStage: () => useDepositStage
});
module.exports = __toCommonJS(useDepositStage_exports);
var import_react = require("react");
var import_decimal = __toESM(require("decimal.js"));
var import_useCustomerGuard = require("./useCustomerGuard");
function useDepositStage({
  isDeposit,
  depositAmount,
  paymentItems = []
}) {
  return (0, import_react.useMemo)(() => {
    const depositTarget = new import_decimal.default(depositAmount || 0);
    const depositPaid = paymentItems.reduce((sum, payment) => {
      if ((payment == null ? void 0 : payment.status) === "voided") return sum;
      if ((payment == null ? void 0 : payment.order_payment_type) !== "deposit" && (payment == null ? void 0 : payment.type) !== "deposit") {
        return sum;
      }
      return sum.plus(payment.amount || 0).minus(payment.rounding_amount || 0);
    }, new import_decimal.default(0));
    const hasNormalPayment = paymentItems.some((payment) => {
      if ((payment == null ? void 0 : payment.status) === "voided") return false;
      if ((0, import_useCustomerGuard.isWalletPassPayment)(payment)) return false;
      return (payment == null ? void 0 : payment.order_payment_type) !== "deposit" && (payment == null ? 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]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useDepositStage
});
