var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/salesSdk/utils/resolveInCartQuantityForAddToast.ts
var resolveInCartQuantityForAddToast_exports = {};
__export(resolveInCartQuantityForAddToast_exports, {
  resolveInCartQuantityForAddToast: () => resolveInCartQuantityForAddToast
});
module.exports = __toCommonJS(resolveInCartQuantityForAddToast_exports);
var import_mergeBookingsForDisplay = require("./mergeBookingsForDisplay");
function resolveInCartQuantityForAddToast(cartItems, productId, bookings = []) {
  const id = String(productId);
  const fromItems = cartItems.reduce((sum, line) => {
    if (String(line.product_id) !== id) return sum;
    const qty = Number(line.num);
    return sum + (Number.isFinite(qty) && qty > 0 ? qty : 0);
  }, 0);
  const fromBookings = bookings.reduce((sum, booking) => {
    var _a;
    const product = (_a = booking._extend) == null ? void 0 : _a.product;
    if (!product || String(product.product_id) !== id) return sum;
    return sum + (0, import_mergeBookingsForDisplay.resolveBookingDisplayQuantity)(product);
  }, 0);
  return fromItems + fromBookings;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  resolveInCartQuantityForAddToast
});
