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/pisellReservation/data/reservationTablesMerge.ts
var reservationTablesMerge_exports = {};
__export(reservationTablesMerge_exports, {
  buildReservationMergedTableRows: () => buildReservationMergedTableRows,
  normalizeSalesResourceBookingListResult: () => normalizeSalesResourceBookingListResult
});
module.exports = __toCommonJS(reservationTablesMerge_exports);
var import_bookingToReservationTables = require("./bookingToReservationTables");
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) {
    if (process.env.NODE_ENV !== "production") {
      console.warn(
        "[buildReservationMergedTableRows] 使用 dataSourcesProp 已有 tables，跳过资源+预约合并",
        {
          gridDataSourceKey,
          fromPropLength: fromProp.length,
          floorDayBookingCount: Array.isArray(floorDayBookingList) ? floorDayBookingList.length : 0,
          hint: "若画布/合并行与接口不一致，请清空或删除引擎里该 dataSource key 的默认 tables，或改为空数组。"
        }
      );
    }
    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 bookingsForMerge = salesResourceBookings != null ? salesResourceBookings : floorDayBookingList;
    const bookingRows = (0, import_bookingToReservationTables.bookingListToReservationTableRows)(bookingsForMerge);
    const merged = (0, import_formResourceToReservationTables.mergeResourceRowsWithBookingRows)(resourceRows, bookingRows);
    if (process.env.NODE_ENV !== "production") {
      console.log("[buildReservationMergedTableRows] 已合并 resource + booking", {
        gridDataSourceKey,
        resourceRowCount: resourceRows.length,
        bookingRowCount: bookingRows.length,
        mergedRowCount: merged.length
      });
    }
    return merged;
  }
  const list = dataProp ?? [];
  return (0, import_bookingToReservationTables.bookingListToReservationTableRows)(list);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildReservationMergedTableRows,
  normalizeSalesResourceBookingListResult
});
