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/solution/VenueBooking/utils/dateSummary.ts
var dateSummary_exports = {};
__export(dateSummary_exports, {
  buildDateRangeSummary: () => buildDateRangeSummary
});
module.exports = __toCommonJS(dateSummary_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_timeSlot = require("./timeSlot");
function buildDateRangeSummary(params) {
  const {
    startDate,
    endDate,
    config,
    rawResources,
    resourceProductMap,
    quotationModule,
    resolveConfig
  } = params;
  const result = [];
  const productIds = quotationModule ? [...new Set([...resourceProductMap.values()].flat().map((m) => m.productId))] : [];
  let cursor = (0, import_dayjs.default)(startDate);
  const end = (0, import_dayjs.default)(endDate);
  while (!cursor.isAfter(end)) {
    const date = cursor.format("YYYY-MM-DD");
    const effectiveConfig = (resolveConfig == null ? void 0 : resolveConfig(date)) || config;
    let quotationPriceMap;
    if (quotationModule && productIds.length) {
      const timeLabels = (0, import_timeSlot.generateTimeLabels)(effectiveConfig);
      const timePoints = timeLabels.map((label) => `${date} ${label}`);
      quotationPriceMap = quotationModule.buildProductPriceMap({ productIds, timePoints });
    }
    const grid = (0, import_timeSlot.buildTimeSlotGrid)({
      date,
      config: effectiveConfig,
      rawResources,
      resourceProductMap,
      quotationPriceMap
    });
    let totalSlots = 0;
    let availableSlots = 0;
    let lowestPrice = null;
    for (const resource of grid.resources) {
      for (const slot of resource.slots) {
        if (slot.status === "past" || slot.status === "unavailable")
          continue;
        totalSlots++;
        if (slot.status === "available" || slot.status === "partially_occupied") {
          availableSlots++;
          if (slot.price !== null) {
            const priceNum = Number(slot.price);
            if (Number.isFinite(priceNum) && (lowestPrice === null || priceNum < lowestPrice)) {
              lowestPrice = priceNum;
            }
          }
        }
      }
    }
    let status;
    if (totalSlots === 0) {
      status = "unavailable";
    } else if (availableSlots === 0) {
      status = "sold_out";
    } else if ((totalSlots - availableSlots) / totalSlots >= effectiveConfig.fewLeftThreshold) {
      status = "few_left";
    } else {
      status = "available";
    }
    result.push({
      date,
      status,
      startingPrice: lowestPrice !== null ? lowestPrice.toFixed(2) : null,
      totalSlots,
      availableSlots
    });
    cursor = cursor.add(1, "day");
  }
  return result;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildDateRangeSummary
});
