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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import dayjs from 'dayjs';
/**
 * 图元多段联系人之间的间隔（中点两侧为 nbsp）。
 * 普通空格在部分 inline-flex / flex 排版下会与相邻文本折叠，看起来像「了点没空格」。
 */
export var FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP = "\xA0\xB7\xA0";
function normalizeHmsForDayjs(time) {
  var t = time.trim();
  var parts = t.split(':').map(function (p) {
    return p.trim();
  });
  if (parts.length >= 2) {
    var h = String(parts[0]).padStart(2, '0');
    var m = String(parts[1]).padStart(2, '0');
    var s = parts[2] != null ? String(parts[2]).padStart(2, '0') : '00';
    return "".concat(h, ":").concat(m, ":").concat(s);
  }
  return '00:00:00';
}
function bookingStartEndMs(startDate, startTime, endDate, endTime) {
  var s = dayjs("".concat(startDate, "T").concat(normalizeHmsForDayjs(startTime))).valueOf();
  var e = dayjs("".concat(endDate, "T").concat(normalizeHmsForDayjs(endTime))).valueOf();
  return {
    start: s,
    end: e
  };
}

/** 统一的起止毫秒（供资源墙/卡片兼容层复用，避免重复推断） */
export function floorRoomCardBookingStartEndMs(booking) {
  return bookingStartEndMs(booking.start_date, booking.start_time, booking.end_date, booking.end_time);
}

/** 日程时刻按展示「整分」对齐（该分钟 00.000） */
export function reservationScheduleMinuteFloorMs(ms) {
  if (!Number.isFinite(ms)) return ms;
  return dayjs(ms).startOf('minute').valueOf();
}

/**
 * 大屏等资源墙：写在日程上的「结束」表示该分钟整段结束前不算 overtime；
 * expired 从「结束时刻所在分钟的下一分钟」整点开始。
 * 例：结束 9:00 → 9:00:00～9:00:59 仍 non-expired，9:01:00 起 expired。
 */
export function reservationScheduleOccupiedOvertimeThresholdMs(endMs) {
  return reservationScheduleMinuteFloorMs(endMs) + 60000;
}

/**
 * 大屏等资源墙：未到「开始分钟」的下一分钟整点不算迟到（与结束侧对称）。
 * 例：开始 8:00 → 8:00:00～8:00:59 仍 boardingSoon，8:01:00 起 late。
 */
export function reservationScheduleReservedLateThresholdMs(startMs) {
  return reservationScheduleMinuteFloorMs(startMs) + 60000;
}

/**
 * 预留态时间行：图元内仅展示时刻 + 文案后缀，不展示开始日期。
 */
export function formatFloorRoomCardBookingStartLine(booking, endSuffix) {
  var _booking$start_time;
  var hm = String((_booking$start_time = booking.start_time) !== null && _booking$start_time !== void 0 ? _booking$start_time : '').trim();
  if (hm) return "".concat(hm, " ").concat(endSuffix).trim();
  return endSuffix;
}

/**
 * 占用态时间行：图元内仅展示结束时刻 + 后缀，不展示结束日期。
 */
export function formatFloorRoomCardBookingEndLine(booking, endSuffix) {
  var _booking$end_time;
  var hm = String((_booking$end_time = booking.end_time) !== null && _booking$end_time !== void 0 ? _booking$end_time : '').trim();
  if (hm) return "".concat(hm, " ").concat(endSuffix).trim();
  return endSuffix;
}

/**
 * 「下一条」等时段：图元内只写起止时刻，不写日期。
 */
export function formatFloorRoomCardBookingTimeRange(booking) {
  var _booking$start_time2, _booking$end_time2;
  var st = String((_booking$start_time2 = booking.start_time) !== null && _booking$start_time2 !== void 0 ? _booking$start_time2 : '').trim();
  var et = String((_booking$end_time2 = booking.end_time) !== null && _booking$end_time2 !== void 0 ? _booking$end_time2 : '').trim();
  if (st && et) return "".concat(st, " - ").concat(et);
  return st || et || '';
}

/** 预约时段内进度 0–100（与 demo getProgressPercent 一致，使用真实时间） */
export function getFloorRoomCardProgressPercent(startDate, startTime, endDate, endTime) {
  var nowMs = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Date.now();
  var _bookingStartEndMs = bookingStartEndMs(startDate, startTime, endDate, endTime),
    start = _bookingStartEndMs.start,
    end = _bookingStartEndMs.end;
  if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return 0;
  if (nowMs <= start) return 0;
  if (nowMs >= end) return 100;
  return Math.round((nowMs - start) / (end - start) * 100);
}

/**
 * 进度条百分比：优先宿主 `progressPercent`（0–100），否则按起止时间与当前时刻推算。
 */
export function resolveFloorRoomCardProgressPercent(booking) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var p = booking.progressPercent;
  if (p != null && Number.isFinite(p)) {
    return Math.min(100, Math.max(0, Math.round(p)));
  }
  return getFloorRoomCardProgressPercent(booking.start_date, booking.start_time, booking.end_date, booking.end_time, nowMs);
}

/** 将分钟数格式化为「10m」「1h 5m」等（图元迟到/超时展示） */
export function formatFloorRoomCardDurationMinutes(totalMin) {
  if (totalMin <= 0) return '0m';
  var h = Math.floor(totalMin / 60);
  var m = totalMin % 60;
  if (h > 0) return m > 0 ? "".concat(h, "h ").concat(m, "m") : "".concat(h, "h");
  return "".concat(m, "m");
}

/** 已超过结束时刻的加时时长文案 */
export function getFloorRoomCardOvertime(endDate, endTime) {
  var nowMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Date.now();
  var _bookingStartEndMs2 = bookingStartEndMs(endDate, endTime, endDate, endTime),
    end = _bookingStartEndMs2.end;
  if (!Number.isFinite(end)) return null;
  var diffMin = Math.floor((nowMs - end) / 60000);
  if (diffMin <= 0) return null;
  return formatFloorRoomCardDurationMinutes(diffMin);
}

/** 已逾开始时刻的「迟到」时长 */
export function getFloorRoomCardLateTime(startDate, startTime) {
  var nowMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Date.now();
  var _bookingStartEndMs3 = bookingStartEndMs(startDate, startTime, startDate, startTime),
    start = _bookingStartEndMs3.start;
  if (!Number.isFinite(start)) return null;
  var diffMin = Math.floor((nowMs - start) / 60000);
  if (diffMin <= 0) return null;
  return formatFloorRoomCardDurationMinutes(diffMin);
}

/** 距开始时刻的倒计时分钟（不含文案前缀）；仅本地起止时间推算 */
export function getFloorRoomCardArrivalMinutes(room) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var b = room.bookings[0];
  if (!b || room.status !== 'reserved') return null;
  var _bookingStartEndMs4 = bookingStartEndMs(b.start_date, b.start_time, b.end_date, b.end_time),
    start = _bookingStartEndMs4.start;
  if (!Number.isFinite(start)) return null;
  var diffMin = Math.floor((start - nowMs) / 60000);
  if (diffMin < 0) return null;
  return diffMin;
}

/**
 * 预留态「还有 n 分钟」：优先宿主 `remainingReserveTime`（分钟，>0），否则 {@link getFloorRoomCardArrivalMinutes}
 */
export function resolveFloorRoomCardReservedCountdownMinutes(room) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var b = room.bookings[0];
  if (!b || room.status !== 'reserved') return null;
  var r = b.remainingReserveTime;
  if (r != null && Number.isFinite(r)) {
    var n = Math.max(0, Math.round(r));
    if (n > 0) return n;
  }
  return getFloorRoomCardArrivalMinutes(room, nowMs);
}

/**
 * 多预约列表中单条：与 {@link resolveFloorRoomCardReservedCountdownMinutes} 一致，但针对当前行 booking。
 */
export function resolveFloorRoomCardReservedCountdownMinutesForBooking(booking) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var r = booking.remainingReserveTime;
  if (r != null && Number.isFinite(r)) {
    var n = Math.max(0, Math.round(r));
    if (n > 0) return n;
  }
  var _bookingStartEndMs5 = bookingStartEndMs(booking.start_date, booking.start_time, booking.end_date, booking.end_time),
    start = _bookingStartEndMs5.start;
  if (!Number.isFinite(start)) return null;
  var diffMin = Math.floor((start - nowMs) / 60000);
  if (diffMin < 0) return null;
  return diffMin;
}

/**
 * 紧凑多预约行：仅当该条 booking 有宿主 `lateTime`（分钟）时为 late，否则 not_arrived（不按本地时刻推算迟到）。
 */
export function getFloorRoomCardReservedRowBodyType(booking) {
  var _nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  if (booking.lateTime != null && Number.isFinite(booking.lateTime) && booking.lateTime > 0) {
    return 'late';
  }
  return 'not_arrived';
}
/** 当前时刻是否落在预约时段内 [start, end)（进行中） */
export function isFloorRoomCardBookingInProgress(booking) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var _bookingStartEndMs6 = bookingStartEndMs(booking.start_date, booking.start_time, booking.end_date, booking.end_time),
    start = _bookingStartEndMs6.start,
    end = _bookingStartEndMs6.end;
  if (!Number.isFinite(start) || !Number.isFinite(end) || end <= start) return false;
  return nowMs >= start && nowMs < end;
}

/** 当前时刻是否在预约开始之前（未开始） */
export function isFloorRoomCardBookingNotStarted(booking) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var _bookingStartEndMs7 = bookingStartEndMs(booking.start_date, booking.start_time, booking.end_date, booking.end_time),
    start = _bookingStartEndMs7.start;
  if (!Number.isFinite(start)) return false;
  return nowMs < start;
}

/**
 * 第一条预约进行中且其后仍有未开始的时段：返回第一条「未开始」预约，用于 Next 行。
 * 不依赖 cardType（不必 late/timeout）。
 */
export function getFloorRoomCardNextNotStartedBooking(data) {
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  var list = data.bookings;
  if (list.length < 2) return null;
  if (!isFloorRoomCardBookingInProgress(list[0], nowMs)) return null;
  for (var i = 1; i < list.length; i++) {
    if (isFloorRoomCardBookingNotStarted(list[i], nowMs)) return list[i];
  }
  return null;
}
function sortFloorRoomCardBookingsByStart(list) {
  return _toConsumableArray(list).sort(function (a, b) {
    var _bookingStartEndMs8 = bookingStartEndMs(a.start_date, a.start_time, a.end_date, a.end_time),
      as = _bookingStartEndMs8.start;
    var _bookingStartEndMs9 = bookingStartEndMs(b.start_date, b.start_time, b.end_date, b.end_time),
      bs = _bookingStartEndMs9.start;
    return as - bs;
  });
}

/**
 * 多条预约里恰好一条 `hostBookingStatus === 'occupied'` 时：把该条排到首位，便于标准占用卡用 bookings[0] 展示。
 * 多条同时为 occupied 或未标记 host 时不改顺序。
 */
export function reorderBookingsForSingleOccupiedPrimary(list) {
  if (list.length <= 1) return list;
  var occ = list.filter(function (b) {
    return b.hostBookingStatus === 'occupied';
  });
  if (occ.length !== 1) return list;
  var sorted = sortFloorRoomCardBookingsByStart(list);
  var occIdx = sorted.findIndex(function (b) {
    return b.hostBookingStatus === 'occupied';
  });
  if (occIdx < 0) return list;
  var primary = sorted[occIdx];
  /** 当前占用之后的时段在前，便于 bookings[1] 与「下一条」一致 */
  var after = sorted.slice(occIdx + 1);
  var before = sorted.slice(0, occIdx);
  return [primary].concat(_toConsumableArray(after), _toConsumableArray(before));
}

/**
 * 多条预约且仅一条为 occupied：按开始时间排序后，取占用段之后的下一条（用于 Next 行）。
 */
export function getFloorRoomCardNextAfterSingleOccupiedBooking(data) {
  var list = data.bookings;
  if (list.length < 2) return null;
  if (list.filter(function (b) {
    return b.hostBookingStatus === 'occupied';
  }).length !== 1) {
    return null;
  }
  var sorted = sortFloorRoomCardBookingsByStart(list);
  var i = sorted.findIndex(function (b) {
    return b.hostBookingStatus === 'occupied';
  });
  if (i < 0 || i >= sorted.length - 1) return null;
  return sorted[i + 1];
}

/**
 * 多条均为预留（无 occupied）：`bookings` 已按开始时间排好，主卡为 [0]，Next 为紧邻的下一条。
 */
export function getFloorRoomCardNextAfterPrimaryReserved(data) {
  var _data$bookings$;
  if (data.status !== 'reserved' || data.bookings.length < 2) return null;
  if (data.bookings.some(function (b) {
    return b.hostBookingStatus === 'occupied';
  })) {
    return null;
  }
  return (_data$bookings$ = data.bookings[1]) !== null && _data$bookings$ !== void 0 ? _data$bookings$ : null;
}

/**
 * 接口标记 `isNext` 的预约：按开始时间取第一条，供 Next 行展示。
 */
export function getFloorRoomCardExplicitNextBooking(data) {
  var _sortFloorRoomCardBoo;
  var marked = data.bookings.filter(function (b) {
    return b.isNext === true;
  });
  if (marked.length === 0) return null;
  return (_sortFloorRoomCardBoo = sortFloorRoomCardBookingsByStart(marked)[0]) !== null && _sortFloorRoomCardBoo !== void 0 ? _sortFloorRoomCardBoo : null;
}

/**
 * 与 {@link buildCardBodyViewModel} Next 行同一套优先级：接口 `is_next`/`isNext` →
 * 单 occupied 后一条 → 多条 reserved 第二条 →「进行中」后首条未开始。
 */
export function resolveFloorRoomCardNextBookingLikeBodyModel(data) {
  var _ref, _ref2, _getFloorRoomCardExpl;
  var nowMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
  return (_ref = (_ref2 = (_getFloorRoomCardExpl = getFloorRoomCardExplicitNextBooking(data)) !== null && _getFloorRoomCardExpl !== void 0 ? _getFloorRoomCardExpl : getFloorRoomCardNextAfterSingleOccupiedBooking(data)) !== null && _ref2 !== void 0 ? _ref2 : getFloorRoomCardNextAfterPrimaryReserved(data)) !== null && _ref !== void 0 ? _ref : getFloorRoomCardNextNotStartedBooking(data, nowMs);
}

/** Next 条客人一行：与图元同源，多层联系人用 ` · ` 拼接 */
export function formatFloorRoomCardNextGuestStripLine(b) {
  return floorRoomCardGuestSegments(b, true).join(FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP);
}

/** 单层 holder：姓名优先；预留态可手机号尾号脱敏 */
export function formatFloorRoomCardGuestDisplayLineFromHolder(holder, showPhone) {
  var _holder$name;
  var n = holder === null || holder === void 0 || (_holder$name = holder.name) === null || _holder$name === void 0 ? void 0 : _holder$name.trim();
  if (n) return n;
  if (showPhone && holder !== null && holder !== void 0 && holder.phone) {
    var m = maskPisellReservationPhoneTail(holder.phone);
    if (m) return m;
  }
  return '';
}
function dedupeAdjacentDuplicateStrings(lines) {
  var out = [];
  var _iterator = _createForOfIteratorHelper(lines),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var L = _step.value;
      if (!L) continue;
      if (out.length === 0 || out[out.length - 1] !== L) out.push(L);
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  return out;
}

/**
 * 图元联系人：按 holder → contacts_info → customer 各层格式化后合并；
 * 无 {@link FloorRoomCardBooking.contactTiers} 时退化为单层 {@link FloorRoomCardBooking.holder}。
 */
export function floorRoomCardGuestSegments(booking, showPhone) {
  var tiers = booking.contactTiers;
  if (tiers !== null && tiers !== void 0 && tiers.length) {
    var lines = tiers.map(function (t) {
      return formatFloorRoomCardGuestDisplayLineFromHolder(_objectSpread({
        name: t.name
      }, t.phone ? {
        phone: t.phone
      } : {}), showPhone).trim();
    });
    return dedupeAdjacentDuplicateStrings(lines.filter(Boolean));
  }
  var fb = formatFloorRoomCardGuestDisplayLineFromHolder(booking.holder, showPhone).trim();
  return fb ? [fb] : [];
}

/**
 * 联系人展示字符串（单层或多层 ` · `）；与平面图 / 资源墙单行摘要一致。
 */
export function formatFloorRoomCardGuestDisplayLine(booking, showPhone) {
  return floorRoomCardGuestSegments(booking, showPhone).join(FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP);
}

/**
 * 主区域展示用：第一条非 `isNext`；若全部为 next 则回退首条。
 */
export function getFloorRoomCardPrimaryBooking(data) {
  var non = data.bookings.find(function (b) {
    return b.isNext !== true;
  });
  return non !== null && non !== void 0 ? non : data.bookings[0];
}

/**
 * 多条预约且均为预留态（host 为 reserved 或未标）：按开始时间排序，主卡只展示最近一档，其余走 Next。
 */
export function reorderBookingsAllReservedChronological(list) {
  if (list.length <= 1) return list;
  if (list.some(function (b) {
    return b.hostBookingStatus === 'occupied';
  })) return list;
  if (!list.every(function (b) {
    return b.hostBookingStatus == null || b.hostBookingStatus === 'reserved';
  })) {
    return list;
  }
  return sortFloorRoomCardBookingsByStart(list);
}

/** 与 demo getCardType 一致 */
export function getFloorRoomCardType(room) {
  if (room.status === 'locked') return 'locked';
  if (room.status === 'empty') return 'empty';
  /**
   * 多条 / 单条判定一律基于「主档预约」，即排除被业务标记为 `isNext` 的下一档预约。
   * 历史实现里这个豁免只在 reserved 态做了一次（"1 reserved + 1 next ≈ 单条 + Next 条带"），
   * occupied 态没做，导致"1 用餐中 + 1 Next"也被判成 multi_occupied，body 走 `.rc-compact` 紧凑排，
   * 与设计预期"主档单条 = 单条卡 + 底部 Next 条带"不一致。这里把豁免推广到通用：
   *   - 主档 ≤ 1 条 → 一律走标准单条卡分支（剩下若有 isNext 由 RoomCardBodyView 的 Next 条带渲染）
   *   - 主档 ≥ 2 条 → 才进入 multi_* 列表卡分支
   */
  var mainBookings = room.bookings.filter(function (b) {
    return b.isNext !== true;
  });
  var occCount = mainBookings.filter(function (b) {
    return b.hostBookingStatus === 'occupied';
  }).length;
  if (mainBookings.length > 1) {
    if (room.status === 'reserved' && occCount === 0) {
      return 'multi_reserved';
    }
    var withHost = mainBookings.filter(function (b) {
      return b.hostBookingStatus != null;
    });
    if (withHost.length > 0) {
      if (occCount >= 2) {
        return 'multi_occupied';
      }
      if (occCount === 1 && room.status === 'occupied') {
        var s = room.sub_status;
        if (s === 'payed' || s === 'payment_required' || s === 'timeout') return s;
        return 'payed';
      }
      if (withHost.every(function (b) {
        return b.hostBookingStatus === 'reserved';
      })) {
        var _s = room.sub_status;
        if (_s === 'not_arrived' || _s === 'late') return _s;
        return 'not_arrived';
      }
    }
    if (room.status === 'occupied') {
      var _s2 = room.sub_status;
      if (_s2 === 'payed' || _s2 === 'payment_required' || _s2 === 'timeout') return _s2;
      return 'payed';
    }
    if (room.status === 'reserved') {
      var _s3 = room.sub_status;
      if (_s3 === 'not_arrived' || _s3 === 'late') return _s3;
      return 'not_arrived';
    }
  }
  if (room.status === 'occupied') {
    var _s4 = room.sub_status;
    if (_s4 === 'payed' || _s4 === 'payment_required' || _s4 === 'timeout') return _s4;
    return 'payed';
  }
  if (room.status === 'reserved') {
    var _s5 = room.sub_status;
    if (_s5 === 'not_arrived' || _s5 === 'late') return _s5;
    return 'not_arrived';
  }
  return 'empty';
}

/**
 * 平面图 RoomCard 联系人手机号展示：与 {@link ReservationFloorRoomCard} ContactInfo 一致。
 */
export function maskPisellReservationPhoneTail(phone) {
  return phone.length >= 4 ? "***".concat(phone.slice(-4)) : null;
}

/**
 * 房间标题：优先数据行 `main_field` 展示名（` ## ` 前为主名称），其次 `code`，最后图元编辑名。
 * 与平面图 `reservationCards` 绑定桌位卡一致。
 */
export function displayRoomTitleFromRow(row, sceneElementName) {
  var _row$code;
  var rawMain = row.main_field;
  if (typeof rawMain === 'string' && rawMain.trim()) {
    var _rawMain$split$;
    var first = (_rawMain$split$ = rawMain.split(' ## ')[0]) === null || _rawMain$split$ === void 0 ? void 0 : _rawMain$split$.trim();
    if (first) return first;
  }
  var c = (_row$code = row.code) === null || _row$code === void 0 ? void 0 : _row$code.trim();
  if (c) return c;
  var n = sceneElementName === null || sceneElementName === void 0 ? void 0 : sceneElementName.trim();
  if (n) return n;
  return '';
}

/**
 * 展示用名称：`main_field` 按 ` ## ` 分段且有两段及以上时取**第二段**（常见「内部码 ## 展示名」），
 * 否则取第一段；再无则回退 {@link displayRoomTitleFromRow}。
 */
export function displayRoomShowNameFromRow(row, sceneElementName) {
  var rawMain = row.main_field;
  if (typeof rawMain === 'string' && rawMain.trim()) {
    var parts = rawMain.split(' ## ').map(function (p) {
      return p.trim();
    }).filter(function (p) {
      return p.length > 0;
    });
    if (parts.length >= 2) return parts[1];
    if (parts.length === 1) return parts[0];
  }
  return displayRoomTitleFromRow(row, sceneElementName);
}