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/booking/info/service/serviceManager/distributeDiscount.ts
var distributeDiscount_exports = {};
__export(distributeDiscount_exports, {
  distributeDiscountOrIncrease: () => distributeDiscountOrIncrease
});
module.exports = __toCommonJS(distributeDiscount_exports);
var import_decimal = __toESM(require("decimal.js"));
function distributeDiscountOrIncrease(products, totalAdjustment, totalPrice) {
  const totalAdjustmentDecimal = new import_decimal.default(totalAdjustment);
  let totalAdjustmentApplied = new import_decimal.default(0);
  const adjustedProducts = [];
  products.forEach((product) => {
    const productPrice = new import_decimal.default(product._extend.origin_total);
    let adjustmentAmount = productPrice.div(totalPrice).times(totalAdjustmentDecimal).toFixed(2, import_decimal.default.ROUND_HALF_UP);
    const newPrice = productPrice.plus(adjustmentAmount).toFixed(2, import_decimal.default.ROUND_HALF_UP);
    const adjustedPrice = new import_decimal.default(newPrice).lessThan(0) ? "0.00" : newPrice;
    adjustedProducts.push({
      ...product,
      _extend: {
        ...product._extend,
        total: parseFloat(adjustedPrice)
      }
    });
    totalAdjustmentApplied = totalAdjustmentApplied.plus(new import_decimal.default(adjustmentAmount));
  });
  const finalTotalPrice = adjustedProducts.reduce(
    (sum, product) => sum.plus(new import_decimal.default(product._extend.total)),
    new import_decimal.default(0)
  );
  const adjustmentDifference = new import_decimal.default(totalPrice).minus(finalTotalPrice).plus(new import_decimal.default(totalAdjustment));
  if (!adjustmentDifference.isZero()) {
    let lastProduct = adjustedProducts[adjustedProducts.length - 1];
    let lastPrice = new import_decimal.default(lastProduct._extend.total).plus(adjustmentDifference).toFixed(2, import_decimal.default.ROUND_HALF_UP);
    lastPrice = new import_decimal.default(lastPrice).lessThan(0) ? "0.00" : lastPrice;
    lastProduct._extend.total = parseFloat(lastPrice);
  }
  return adjustedProducts;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  distributeDiscountOrIncrease
});
