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/plus/pisellReservation/data/reservationTablesMerge.ts
var reservationTablesMerge_exports = {};
__export(reservationTablesMerge_exports, {
  buildReservationMergedTableRows: () => buildReservationMergedTableRows,
  normalizeSalesResourceBookingListResult: () => normalizeSalesResourceBookingListResult
});
module.exports = __toCommonJS(reservationTablesMerge_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_bookingToReservationTables = require("./bookingToReservationTables");
var import_filterBookingsAtTimeCursor = require("./filterBookingsAtTimeCursor");
var import_formResourceToReservationTables = require("./formResourceToReservationTables");
var import_salesEmbeddedResourceToTableRows = require("./salesEmbeddedResourceToTableRows");
function normalizeSalesResourceBookingListResult(raw) {
  if (raw == null) return [];
  if (Array.isArray(raw)) return raw;
  if (typeof raw === "object") {
    const o = raw;
    if (Array.isArray(o.list)) return o.list;
    if (Array.isArray(o.data)) return o.data;
    if (Array.isArray(o.records)) return o.records;
  }
  return [];
}
function buildReservationMergedTableRows(options) {
  const {
    dataSourcesProp,
    gridDataSourceKey,
    isInternalListData,
    resourceList,
    floorDayBookingList,
    schedule,
    dataProp,
    salesResourceBookings
  } = options;
  const fromProp = dataSourcesProp == null ? void 0 : dataSourcesProp[gridDataSourceKey];
  if (Array.isArray(fromProp) && fromProp.length > 0) return fromProp;
  if (isInternalListData) {
    if (salesResourceBookings != null && (0, import_salesEmbeddedResourceToTableRows.isSalesEmbeddedResourceBookingsList)(salesResourceBookings)) {
      return (0, import_salesEmbeddedResourceToTableRows.salesEmbeddedResourceListToTableRows)(salesResourceBookings);
    }
    const resourceRows = (0, import_formResourceToReservationTables.formResourceListToReservationTableRows)(resourceList);
    const cursorAt = schedule.at != null && (0, import_dayjs.default)(schedule.at).isValid() ? (0, import_dayjs.default)(schedule.at) : (0, import_dayjs.default)();
    const atCursor = salesResourceBookings != null ? salesResourceBookings : (0, import_filterBookingsAtTimeCursor.filterBookingsVisibleAtTimeCursor)(floorDayBookingList, cursorAt);
    const bookingRows = (0, import_bookingToReservationTables.bookingListToReservationTableRows)(atCursor);
    return (0, import_formResourceToReservationTables.mergeResourceRowsWithBookingRows)(resourceRows, bookingRows);
  }
  const list = dataProp ?? [];
  return (0, import_bookingToReservationTables.bookingListToReservationTableRows)(list);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildReservationMergedTableRows,
  normalizeSalesResourceBookingListResult
});
