import { PISELL_FLOOR_CHECKOUT_BOOKING_SELECTOR } from "../reservationConstants.js";
//#region src/plus/pisellReservation/floorMap/floorMapHostCheckout.ts
/**
* 根据点击目标解析要交给宿主的预约行：多预约卡片上子块带
* {@link PISELL_FLOOR_CHECKOUT_BOOKING_SELECTOR} 时命中对应项，否则取列表首条。
*/
function resolveFloorMapHostCheckoutRecord(event, sourceBookings) {
	var _el$getAttribute;
	if (!(sourceBookings === null || sourceBookings === void 0 ? void 0 : sourceBookings.length)) return void 0;
	const root = event.target;
	if (!root) return sourceBookings[0];
	const el = root.closest(PISELL_FLOOR_CHECKOUT_BOOKING_SELECTOR);
	const 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) {
		const hit = sourceBookings.find((r) => {
			const rid = r.id;
			const 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;
	}
	const first = sourceBookings[0];
	return first && typeof first === "object" ? first : void 0;
}
//#endregion
export { resolveFloorMapHostCheckoutRecord };
