function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
/**
 * 内置列表模式下：资源台位行（每张桌 id=平面图 dataBinding.recordId） +
 * 当日预约列表（宿主 getResourceBookingList 或 `floorDayBookingList`）→ merge 成平面图 dataSources.tables。
 * 预约子集由接口侧 `form_record_ids`（画布绑定资源）与 `booking_time_start_between`（营业日窗）约束，
 * **不再**按顶栏日程 `at` 游标做「当前时刻可见」二次筛选。
 */

import { bookingListToReservationTableRows } from "./bookingToReservationTables";
import { formResourceListToReservationTableRows, mergeResourceRowsWithBookingRows } from "./formResourceToReservationTables";
import { isSalesEmbeddedResourceBookingsList, salesEmbeddedResourceListToTableRows } from "./salesEmbeddedResourceToTableRows";
/**
 * 将宿主 `sales.getResourceBookingList` 的返回值规范为 booking 项数组（便于走 bookingListToReservationTableRows）
 */
export function normalizeSalesResourceBookingListResult(raw) {
  if (raw == null) return [];
  if (Array.isArray(raw)) return raw;
  if (_typeof(raw) === 'object') {
    var 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 [];
}
export function buildReservationMergedTableRows(options) {
  var dataSourcesProp = options.dataSourcesProp,
    gridDataSourceKey = options.gridDataSourceKey,
    isInternalListData = options.isInternalListData,
    resourceList = options.resourceList,
    floorDayBookingList = options.floorDayBookingList,
    schedule = options.schedule,
    dataProp = options.dataProp,
    salesResourceBookings = options.salesResourceBookings;
  void schedule;
  var fromProp = dataSourcesProp === null || dataSourcesProp === void 0 ? void 0 : dataSourcesProp[gridDataSourceKey];
  if (Array.isArray(fromProp) && fromProp.length > 0) {
    /**
     * 低代码若预置非空 tables，此处会直接返回，**不会**与 floorDay 预约合并。
     * 该提示仅在排查画布无数据时有用，落生产 / 实时推送热路径会成为序列化大对象的瓶颈，
     * 故仅在非生产构建下输出。
     */
    if (process.env.NODE_ENV !== 'production') {
      // eslint-disable-next-line no-console
      console.warn('[buildReservationMergedTableRows] 使用 dataSourcesProp 已有 tables，跳过资源+预约合并', {
        gridDataSourceKey: gridDataSourceKey,
        fromPropLength: fromProp.length,
        floorDayBookingCount: Array.isArray(floorDayBookingList) ? floorDayBookingList.length : 0,
        hint: '若画布/合并行与接口不一致，请清空或删除引擎里该 dataSource key 的默认 tables，或改为空数组。'
      });
    }
    return fromProp;
  }
  if (isInternalListData) {
    /**
     * 宿主 `getResourceBookingList` 若返回「每行一桌位 + bookings[]」，与扁平预约数组区分，
     * 直接生成 tables（id/main_field 与 OS 一致，预约已挂在该行下）。
     */
    if (salesResourceBookings != null && isSalesEmbeddedResourceBookingsList(salesResourceBookings)) {
      return salesEmbeddedResourceListToTableRows(salesResourceBookings);
    }
    var resourceRows = formResourceListToReservationTableRows(resourceList);
    var bookingsForMerge = salesResourceBookings != null ? salesResourceBookings : floorDayBookingList;
    var bookingRows = bookingListToReservationTableRows(bookingsForMerge);
    var merged = mergeResourceRowsWithBookingRows(resourceRows, bookingRows);
    /**
     * 该 merge 在 WS 推送链路里每次都会跑；`merged.find(...)` + DevTools 序列化整个 row
     * 单次 100ms+，是「推送 → 画布」延迟的主要来源。仅在非生产下保留排查日志。
     */
    if (process.env.NODE_ENV !== 'production') {
      // eslint-disable-next-line no-console
      console.log('[buildReservationMergedTableRows] 已合并 resource + booking', {
        gridDataSourceKey: gridDataSourceKey,
        resourceRowCount: resourceRows.length,
        bookingRowCount: bookingRows.length,
        mergedRowCount: merged.length
      });
    }
    return merged;
  }
  var list = dataProp !== null && dataProp !== void 0 ? dataProp : [];
  return bookingListToReservationTableRows(list);
}