const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
let dayjs = require("dayjs");
dayjs = require_runtime.__toESM(dayjs);
//#region src/plus/pisellReservation/data/filterBookingsAtTimeCursor.ts
/**
* 平面图时间轴游标：从当日预约列表中筛出「在 cursor 时刻仍有效」的项，避免仅拖动时间重复请求接口。
*/
function parseBookingStart(b) {
	const raw = b.start_at || (b.start_date && b.start_time ? `${b.start_date} ${b.start_time}` : "");
	if (!raw) return null;
	const d = (0, dayjs.default)(raw);
	return d.isValid() ? d : null;
}
function parseBookingEnd(b) {
	const raw = b.end_at || (b.end_date && b.end_time ? `${b.end_date} ${b.end_time}` : "");
	if (!raw) return null;
	const d = (0, dayjs.default)(raw);
	return d.isValid() ? d : null;
}
/**
* 无结束时间时的展示用上界：在座视为持续；纯预订单用默认餐段避免误占满全天。
*/
function displayEndMs(b, start) {
	var _b$status;
	const explicit = parseBookingEnd(b);
	if (explicit) return explicit.valueOf();
	const 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 对齐）
*/
function filterBookingsVisibleAtTimeCursor(bookings, cursor) {
	if (!Array.isArray(bookings) || bookings.length === 0) return [];
	const t = cursor.valueOf();
	return bookings.filter((raw) => {
		var _b$status2;
		if (!raw || typeof raw !== "object") return false;
		const b = raw;
		const 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;
		const start = parseBookingStart(b);
		if (!start) return false;
		if (t < start.valueOf()) return false;
		return t < displayEndMs(b, start);
	});
}
//#endregion
exports.filterBookingsVisibleAtTimeCursor = filterBookingsVisibleAtTimeCursor;
