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 或本地 filterBookingsVisibleAtTimeCursor）
 * → merge 成平面图 dataSources.tables，渲染时无需再查表。
 */
import dayjs from 'dayjs';
import { bookingListToReservationTableRows } from "./bookingToReservationTables";
import { filterBookingsVisibleAtTimeCursor } from "./filterBookingsAtTimeCursor";
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;
  var fromProp = dataSourcesProp === null || dataSourcesProp === void 0 ? void 0 : dataSourcesProp[gridDataSourceKey];
  if (Array.isArray(fromProp) && fromProp.length > 0) return fromProp;
  if (isInternalListData) {
    /**
     * 宿主 `getResourceBookingList` 若返回「每行一桌位 + bookings[]」，与扁平预约数组区分，
     * 直接生成 tables（id/main_field 与 OS 一致，预约已挂在该行下）。
     */
    if (salesResourceBookings != null && isSalesEmbeddedResourceBookingsList(salesResourceBookings)) {
      return salesEmbeddedResourceListToTableRows(salesResourceBookings);
    }
    var resourceRows = formResourceListToReservationTableRows(resourceList);
    var cursorAt = schedule.at != null && dayjs(schedule.at).isValid() ? dayjs(schedule.at) : dayjs();
    var atCursor = salesResourceBookings != null ? salesResourceBookings : filterBookingsVisibleAtTimeCursor(floorDayBookingList, cursorAt);
    var bookingRows = bookingListToReservationTableRows(atCursor);
    return mergeResourceRowsWithBookingRows(resourceRows, bookingRows);
  }
  var list = dataProp !== null && dataProp !== void 0 ? dataProp : [];
  return bookingListToReservationTableRows(list);
}