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); }
/**
 * 平面图时间轴游标：从当日预约列表中筛出「在 cursor 时刻仍有效」的项，避免仅拖动时间重复请求接口。
 */
import dayjs from 'dayjs';
function parseBookingStart(b) {
  var raw = b.start_at || (b.start_date && b.start_time ? "".concat(b.start_date, " ").concat(b.start_time) : '');
  if (!raw) return null;
  var d = dayjs(raw);
  return d.isValid() ? d : null;
}
function parseBookingEnd(b) {
  var raw = b.end_at || (b.end_date && b.end_time ? "".concat(b.end_date, " ").concat(b.end_time) : '');
  if (!raw) return null;
  var d = dayjs(raw);
  return d.isValid() ? d : null;
}

/**
 * 无结束时间时的展示用上界：在座视为持续；纯预订单用默认餐段避免误占满全天。
 */
function displayEndMs(b, start) {
  var _b$status;
  var explicit = parseBookingEnd(b);
  if (explicit) return explicit.valueOf();
  var st = String((_b$status = b.status) !== null && _b$status !== void 0 ? _b$status : '');
  if (st === 'occupied' || st === 'locked') {
    return Number.MAX_SAFE_INTEGER;
  }
  return start.add(2, 'hour').valueOf();
}

/**
 * @param bookings GET booking 列表项（与 bookingToReservationTables 入参一致）
 * @param cursor 顶栏日程带 `at`（与 PisellTimeNavigator 对齐）
 */
export function filterBookingsVisibleAtTimeCursor(bookings, cursor) {
  if (!Array.isArray(bookings) || bookings.length === 0) return [];
  var t = cursor.valueOf();
  return bookings.filter(function (raw) {
    var _b$status2;
    if (!raw || _typeof(raw) !== 'object') return false;
    var b = raw;
    var st = String((_b$status2 = b.status) !== null && _b$status2 !== void 0 ? _b$status2 : '');
    if (st !== 'reserved' && st !== 'occupied' && st !== 'locked') return false;
    if (st === 'locked') return true;
    var start = parseBookingStart(b);
    if (!start) return false;
    var sMs = start.valueOf();
    if (t < sMs) return false;
    var eMs = displayEndMs(b, start);
    return t < eMs;
  });
}