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); }
import { PISELL_FLOOR_CHECKOUT_BOOKING_SELECTOR } from "../reservationConstants";

/**
 * 根据点击目标解析要交给宿主的预约行：多预约卡片上子块带
 * {@link PISELL_FLOOR_CHECKOUT_BOOKING_SELECTOR} 时命中对应项，否则取列表首条。
 */
export function resolveFloorMapHostCheckoutRecord(event, sourceBookings) {
  var _el$getAttribute;
  if (!(sourceBookings !== null && sourceBookings !== void 0 && sourceBookings.length)) return undefined;
  var root = event.target;
  if (!root) return sourceBookings[0];
  var el = root.closest(PISELL_FLOOR_CHECKOUT_BOOKING_SELECTOR);
  var key = el === null || el === void 0 || (_el$getAttribute = el.getAttribute('data-pisell-floor-checkout-booking')) === null || _el$getAttribute === void 0 ? void 0 : _el$getAttribute.trim();
  if (key) {
    var hit = sourceBookings.find(function (r) {
      var rid = r.id;
      var bid = r.booking_id;
      return String(rid !== null && rid !== void 0 ? rid : '') === key || String(bid !== null && bid !== void 0 ? bid : '') === key;
    });
    if (hit && _typeof(hit) === 'object') return hit;
  }
  var first = sourceBookings[0];
  return first && _typeof(first) === 'object' ? first : undefined;
}