import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { reorderBookingsAllReservedChronological, reorderBookingsForSingleOccupiedPrimary } from "./floorRoomCardUtils.js";
import dayjs from "dayjs";
//#region src/plus/pisellReservation/floorRoomCard/mapRowToFloorRoomCardData.ts
/**
* 从接口原始字段解析 HH:mm（展示用，避免 dayjs 解析失败时误用当前时刻）
*/
function coerceHhMm(raw) {
	if (raw == null) return null;
	const s = String(raw).trim();
	if (!s) return null;
	const m = s.match(/^(\d{1,2}):(\d{2})/);
	if (!m) return null;
	return `${m[1].padStart(2, "0")}:${m[2]}`;
}
/** YYYY-MM-DD */
function coerceYmd(raw) {
	if (raw == null) return null;
	const s = String(raw).trim();
	const head = s.slice(0, 10);
	if (/^\d{4}-\d{2}-\d{2}$/.test(head)) return head;
	const d = dayjs(s);
	return d.isValid() ? d.format("YYYY-MM-DD") : null;
}
/** 宿主迟到/超时字段：分钟，非负整数 */
function coerceHostMinutesField(raw) {
	if (raw == null || raw === "") return void 0;
	const n = typeof raw === "number" ? raw : Number(String(raw).trim());
	if (!Number.isFinite(n) || n < 0) return void 0;
	return Math.round(n);
}
/** 宿主进度 0–100 */
function coerceHostProgressPercent(raw) {
	if (raw == null || raw === "") return void 0;
	const n = typeof raw === "number" ? raw : Number(String(raw).trim());
	if (!Number.isFinite(n)) return void 0;
	return Math.min(100, Math.max(0, Math.round(n)));
}
function parseOrderCustomerId(raw) {
	if (raw == null || raw === "") return null;
	const n = typeof raw === "number" ? raw : Number(String(raw).trim());
	return Number.isFinite(n) ? n : null;
}
/** 解析订单客户 id：优先 `order.customer_id`，否则 `order.customer.id` */
function parseBookingOrderCustomerId(order) {
	if (!order) return null;
	const top = parseOrderCustomerId(order.customer_id);
	if (top != null) return top;
	const cust = order.customer;
	if (cust && typeof cust === "object") return parseOrderCustomerId(cust.id);
	return null;
}
/**
* Walk-in / 占位客户：`customer_id`（或 `customer.id`）为 0、1 时，预约侧不展示任何联系人（含 holder / contacts_info）。
*/
function isReservationPlaceholderCustomerId(order) {
	const n = parseBookingOrderCustomerId(order);
	return n === 0 || n === 1;
}
/**
* 第 3 步：客户 id 为有效数字且非占位 0、1 时可用 customer 层级（customer_name / customer / phone）。
*/
function isRealOrderCustomer(order) {
	const n = parseBookingOrderCustomerId(order);
	if (n == null) return false;
	return n !== 0 && n !== 1;
}
/**
* 从 `order.summary` 或回退链取单笔可展示金额（字符串或数字）。
*/
function coalesceSummaryAmount(v) {
	if (v == null || v === "") return null;
	if (typeof v === "number" && Number.isFinite(v)) return v;
	return String(v).trim() !== "" ? v : null;
}
/**
* 平面图/详情卡片展示金额：
* - 已付（`paid`）：仍用 `summary.total_amount` 与原有回退链，逻辑不变。
* - 需付：`payment_processing` 与 `unpaid` → 优先 `summary.total_amount`，否则 `amount_gap` 再顶层回退；
*   其余需付态 → 优先 `summary.amount_gap`，否则 `total_amount` 再顶层回退。
*/
function resolveBookingCardAmount(rawBooking, order, paymentStatusLower) {
	const pay = String(paymentStatusLower !== null && paymentStatusLower !== void 0 ? paymentStatusLower : "").trim().toLowerCase();
	const ord = order;
	const sum = ord === null || ord === void 0 ? void 0 : ord.summary;
	const fallbackChain = () => {
		var _ref, _ref2, _ref3, _ref4, _rawBooking$amount;
		const v = (_ref = (_ref2 = (_ref3 = (_ref4 = (_rawBooking$amount = rawBooking.amount) !== null && _rawBooking$amount !== void 0 ? _rawBooking$amount : rawBooking.total) !== null && _ref4 !== void 0 ? _ref4 : rawBooking.grand_total) !== null && _ref3 !== void 0 ? _ref3 : ord === null || ord === void 0 ? void 0 : ord.total_amount) !== null && _ref2 !== void 0 ? _ref2 : sum === null || sum === void 0 ? void 0 : sum.total_amount) !== null && _ref !== void 0 ? _ref : 0;
		return typeof v === "string" || typeof v === "number" ? v : 0;
	};
	if (pay === "paid") {
		var _ref5, _ref6, _ref7, _sum$total_amount;
		const v = (_ref5 = (_ref6 = (_ref7 = (_sum$total_amount = sum === null || sum === void 0 ? void 0 : sum.total_amount) !== null && _sum$total_amount !== void 0 ? _sum$total_amount : ord === null || ord === void 0 ? void 0 : ord.total_amount) !== null && _ref7 !== void 0 ? _ref7 : rawBooking.amount) !== null && _ref6 !== void 0 ? _ref6 : rawBooking.total) !== null && _ref5 !== void 0 ? _ref5 : fallbackChain();
		return typeof v === "string" || typeof v === "number" ? v : fallbackChain();
	}
	if (pay === "payment_processing" || pay === "unpaid") {
		const fromTotal = coalesceSummaryAmount(sum === null || sum === void 0 ? void 0 : sum.total_amount);
		if (fromTotal != null) return fromTotal;
		const fromGap = coalesceSummaryAmount(sum === null || sum === void 0 ? void 0 : sum.amount_gap);
		if (fromGap != null) return fromGap;
		return fallbackChain();
	}
	const fromGapFirst = coalesceSummaryAmount(sum === null || sum === void 0 ? void 0 : sum.amount_gap);
	if (fromGapFirst != null) return fromGapFirst;
	const fromTotalSecond = coalesceSummaryAmount(sum === null || sum === void 0 ? void 0 : sum.total_amount);
	if (fromTotalSecond != null) return fromTotalSecond;
	return fallbackChain();
}
function countTopLevelProductLinesInRaw(rawBooking) {
	const p = rawBooking.products;
	if (!Array.isArray(p)) return null;
	return p.filter((x) => x && typeof x === "object").length;
}
function parseSummaryProductQuantity(v) {
	if (v == null || v === "") return null;
	if (typeof v === "number" && Number.isFinite(v)) return Math.max(0, Math.round(v));
	const n = Number(String(v).replace(/,/g, "").trim());
	return Number.isFinite(n) ? Math.max(0, Math.round(n)) : null;
}
/** 与预约详情 strip 同源：顶层 products 行数优先，否则 summary.product_quantity */
function resolveBookingProductQuantity(rawBooking) {
	var _parseSummaryProductQ;
	const fromArr = countTopLevelProductLinesInRaw(rawBooking);
	if (fromArr != null) return fromArr;
	const ord = rawBooking.order;
	const sum = ord === null || ord === void 0 ? void 0 : ord.summary;
	return (_parseSummaryProductQ = parseSummaryProductQuantity(sum === null || sum === void 0 ? void 0 : sum.product_quantity)) !== null && _parseSummaryProductQ !== void 0 ? _parseSummaryProductQ : 0;
}
/**
* 联系人第 1 优先：`booking.holder`，其次 `holder_data`（与列表 customerBrief 数据源对齐）。
*/
function holderFromBookingHolderField(b) {
	const h = b.holder;
	if (h && typeof h === "object") {
		const name = typeof h.name === "string" ? h.name.trim() : "";
		let phone;
		if (typeof h.phone === "string" && /\d/.test(h.phone)) phone = h.phone;
		else {
			const po = h.phone;
			if (po && typeof po.phone === "string" && /\d/.test(po.phone)) phone = po.phone;
		}
		if (name || phone) return _objectSpread2({ name }, phone ? { phone } : {});
	}
	const hd = b.holder_data;
	const hx = Array.isArray(hd) ? hd[0] : hd;
	if (hx && typeof hx === "object") {
		const ho = hx;
		if (typeof ho.name === "string" && ho.name.trim()) return { name: ho.name.trim() };
		const data = ho.data;
		const cn = data === null || data === void 0 ? void 0 : data.customer_name;
		if (typeof cn === "string" && cn.trim()) return { name: cn.trim() };
	}
	return null;
}
/** `order.contacts_info`：first_name / last_name / phone.phone */
function contactsInfoContact(order) {
	const ci = order.contacts_info;
	if (!ci || typeof ci !== "object") return null;
	const name = [typeof ci.first_name === "string" ? ci.first_name.trim() : "", typeof ci.last_name === "string" ? ci.last_name.trim() : ""].filter(Boolean).join(" ");
	const phoneObj = ci.phone;
	const ph = phoneObj === null || phoneObj === void 0 ? void 0 : phoneObj.phone;
	const phone = typeof ph === "string" && /\d/.test(ph) ? ph : void 0;
	if (!name && !phone) return null;
	return _objectSpread2({ name }, phone ? { phone } : {});
}
/**
* 平面图 / 详情弹窗 / 列表联系人：与 Pisell Reservation 统一规则。
* - `order.customer_id`（或 `order.customer.id`）为 0、1：不展示任何联系人。
* - 否则顺序：**holder**（`booking.holder` → `holder_data`）→ **contact**（`order.contacts_info`）→ **customer**（`customer_name` / `order.customer` / `order.phone`）。
*/
function resolveFloorRoomCardHolder(b) {
	const ord = b.order;
	if (isReservationPlaceholderCustomerId(ord)) return;
	const rh = holderFromBookingHolderField(b);
	if (rh && (rh.name || rh.phone)) return _objectSpread2({ name: rh.name }, rh.phone ? { phone: rh.phone } : {});
	if (ord) {
		const ci = contactsInfoContact(ord);
		if (ci && (ci.name || ci.phone)) return _objectSpread2({ name: ci.name }, ci.phone ? { phone: ci.phone } : {});
	}
	if (ord && isRealOrderCustomer(ord)) {
		const cn = typeof ord.customer_name === "string" ? ord.customer_name.trim() : "";
		const topPhone = typeof ord.phone === "string" && /\d/.test(ord.phone) ? ord.phone : void 0;
		if (cn || topPhone) return _objectSpread2({ name: cn }, topPhone ? { phone: topPhone } : {});
		const cust = ord.customer;
		if (cust && typeof cust === "object") {
			var _cust$phone;
			const custName = typeof cust.name === "string" && cust.name.trim() || [cust.first_name, cust.last_name].filter(Boolean).join(" ").trim() || typeof cust.company_name === "string" && cust.company_name.trim() || "";
			const custPhoneRaw = (_cust$phone = cust.phone) !== null && _cust$phone !== void 0 ? _cust$phone : cust.mobile;
			const custPhone = typeof custPhoneRaw === "string" && /\d/.test(custPhoneRaw) ? custPhoneRaw : void 0;
			if (custName || custPhone) return _objectSpread2({ name: custName }, custPhone ? { phone: custPhone } : {});
		}
	}
}
/** 单条 floorMapSourceBookings → 与平面图 RoomCard 一致的 booking 模型 */
function rawToBooking(b, index) {
	var _b$id, _ref8, _ref9, _coerceYmd, _scheduleDateStr$spli, _ref10, _coerceHhMm, _ref11, _coerceYmd2, _coerceHhMm2, _b$is_next;
	const orderBookingId = b.booking_id != null && String(b.booking_id) !== "" ? String(b.booking_id) : `b_${(_b$id = b.id) !== null && _b$id !== void 0 ? _b$id : index}`;
	const recordIdRaw = b.id;
	const recordId = recordIdRaw != null && String(recordIdRaw).trim() !== "" ? String(recordIdRaw).trim() : void 0;
	const ord = b.order;
	const scheduleDateStr = typeof (ord === null || ord === void 0 ? void 0 : ord.schedule_date) === "string" ? ord.schedule_date.trim() : "";
	const startYmd = (_ref8 = (_ref9 = (_coerceYmd = coerceYmd(b.start_date)) !== null && _coerceYmd !== void 0 ? _coerceYmd : coerceYmd(b.select_date)) !== null && _ref9 !== void 0 ? _ref9 : scheduleDateStr ? coerceYmd(scheduleDateStr) : null) !== null && _ref8 !== void 0 ? _ref8 : coerceYmd(ord === null || ord === void 0 ? void 0 : ord.create_date);
	const scheduleTimeFromOrder = scheduleDateStr.includes(" ") ? coerceHhMm((_scheduleDateStr$spli = scheduleDateStr.split(/\s+/).slice(-1)[0]) !== null && _scheduleDateStr$spli !== void 0 ? _scheduleDateStr$spli : "") : null;
	const startHm = (_ref10 = (_coerceHhMm = coerceHhMm(b.start_time)) !== null && _coerceHhMm !== void 0 ? _coerceHhMm : scheduleTimeFromOrder) !== null && _ref10 !== void 0 ? _ref10 : coerceHhMm(ord === null || ord === void 0 ? void 0 : ord.start_time);
	const endYmd = (_ref11 = (_coerceYmd2 = coerceYmd(b.end_date)) !== null && _coerceYmd2 !== void 0 ? _coerceYmd2 : startYmd) !== null && _ref11 !== void 0 ? _ref11 : coerceYmd(ord === null || ord === void 0 ? void 0 : ord.create_date);
	let endHm = (_coerceHhMm2 = coerceHhMm(b.end_time)) !== null && _coerceHhMm2 !== void 0 ? _coerceHhMm2 : coerceHhMm(ord === null || ord === void 0 ? void 0 : ord.end_time);
	/**
	* 进度条/倒计时用时刻：优先 booking 的 start_date/start_time（与列表字段一致），
	* 再回退 start_at；绝不使用 Date.now() 冒充预约开始。
	*/
	let startD = null;
	if (startYmd && startHm) {
		const t = dayjs(`${startYmd} ${startHm}`);
		if (t.isValid()) startD = t;
	}
	if (!startD && b.start_at) {
		const t = dayjs(String(b.start_at));
		if (t.isValid()) startD = t;
	}
	let endD = null;
	if (endYmd && endHm) {
		const t = dayjs(`${endYmd} ${endHm}`);
		if (t.isValid()) endD = t;
	}
	if (!endD && b.end_at) {
		const t = dayjs(String(b.end_at));
		if (t.isValid()) endD = t;
	}
	if (!endD && startD && typeof b.duration === "number" && Number.isFinite(b.duration) && String(b.sub_type) === "minutes") {
		const t = startD.add(b.duration, "minute");
		if (t.isValid()) endD = t;
	}
	if (!endD && startD) endD = startD.add(2, "hour");
	const startDateOut = (startD === null || startD === void 0 ? void 0 : startD.isValid()) ? startD.format("YYYY-MM-DD") : startYmd !== null && startYmd !== void 0 ? startYmd : "";
	const startTimeOut = (startD === null || startD === void 0 ? void 0 : startD.isValid()) ? startD.format("HH:mm") : startHm !== null && startHm !== void 0 ? startHm : "--:--";
	let endDateOut = (endD === null || endD === void 0 ? void 0 : endD.isValid()) ? endD.format("YYYY-MM-DD") : endYmd !== null && endYmd !== void 0 ? endYmd : startDateOut;
	let endTimeOut = (endD === null || endD === void 0 ? void 0 : endD.isValid()) ? endD.format("HH:mm") : endHm !== null && endHm !== void 0 ? endHm : "--:--";
	const num = b.number;
	const party = typeof num === "number" && Number.isFinite(num) ? num : Number(num) || 0;
	const lt = coerceHostMinutesField(b.lateTime);
	const tt = coerceHostMinutesField(b.timeoutTime);
	const rr = coerceHostMinutesField(b.remainingReserveTime);
	const pp = coerceHostProgressPercent(b.progressPercent);
	const rawOps = ord === null || ord === void 0 ? void 0 : ord.payment_status;
	const opsTrim = rawOps != null && String(rawOps).trim() !== "" ? String(rawOps).trim() : "";
	const opsLower = opsTrim.toLowerCase();
	/** 仅保留 paid / unpaid：部分付并入 unpaid（需付款） */
	const order_payment_status = opsTrim === "" ? void 0 : opsLower === "paid" ? "paid" : opsLower === "partially_paid" ? "unpaid" : opsTrim;
	const amt = resolveBookingCardAmount(b, ord, opsLower);
	const productQty = resolveBookingProductQuantity(b);
	const holder = resolveFloorRoomCardHolder(b);
	const hostBookingStatus = coerceHostBookingStatusForCard(b);
	const rawIsNext = (_b$is_next = b.is_next) !== null && _b$is_next !== void 0 ? _b$is_next : b.isNext;
	const isNextMarked = rawIsNext === true || rawIsNext === "true" || rawIsNext === 1 || rawIsNext === "1";
	return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({ booking_id: orderBookingId }, recordId ? { recordId } : {}), {}, {
		start_date: startDateOut || startYmd || "",
		start_time: startTimeOut,
		end_date: endDateOut || startDateOut || "",
		end_time: endTimeOut,
		number: party
	}, holder ? { holder } : {}), hostBookingStatus ? { hostBookingStatus } : {}), {}, {
		amount: typeof amt === "string" || typeof amt === "number" ? amt : 0,
		product_quantity: productQty
	}, lt != null && lt > 0 ? { lateTime: lt } : {}), tt != null && tt > 0 ? { timeoutTime: tt } : {}), rr != null && rr > 0 ? { remainingReserveTime: rr } : {}), pp !== void 0 ? { progressPercent: pp } : {}), order_payment_status !== void 0 ? { order_payment_status } : {}), isNextMarked ? { isNext: true } : {});
}
function syntheticFromRow(row) {
	var _row$floorMapReferenc, _trim$split$, _row$time, _row$timeEnd, _row$guestName$trim, _row$guestName, _row$priceDisplay, _row$partySize;
	const day = (_row$floorMapReferenc = row.floorMapReferenceDay) !== null && _row$floorMapReferenc !== void 0 ? _row$floorMapReferenc : dayjs().format("YYYY-MM-DD");
	const startD = dayjs(`${day} ${(_trim$split$ = ((_row$time = row.time) !== null && _row$time !== void 0 ? _row$time : "12:00").trim().split(/\s+/)[0]) !== null && _trim$split$ !== void 0 ? _trim$split$ : "12:00"}`);
	let endD;
	if ((_row$timeEnd = row.timeEnd) === null || _row$timeEnd === void 0 ? void 0 : _row$timeEnd.trim()) {
		const et = row.timeEnd.trim().split(/\s+/)[0];
		endD = dayjs(`${day} ${et}`);
		if (!endD.isValid() || endD.valueOf() <= startD.valueOf()) endD = startD.add(2, "hour");
	} else endD = startD.add(2, "hour");
	const guestPhone = row.guestPhone && !row.guestPhone.includes("*") ? row.guestPhone : void 0;
	const displayName = (_row$guestName$trim = (_row$guestName = row.guestName) === null || _row$guestName === void 0 ? void 0 : _row$guestName.trim()) !== null && _row$guestName$trim !== void 0 ? _row$guestName$trim : "";
	const holderFromRow = displayName || guestPhone ? _objectSpread2({ name: displayName }, guestPhone ? { phone: guestPhone } : {}) : void 0;
	const amt = (_row$priceDisplay = row.priceDisplay) !== null && _row$priceDisplay !== void 0 ? _row$priceDisplay : 0;
	const startsIn = row.startsInMinutes != null && Number.isFinite(row.startsInMinutes) && row.startsInMinutes > 0 ? Math.round(row.startsInMinutes) : void 0;
	const rowLateMin = row.lateMinutes != null && Number.isFinite(row.lateMinutes) && row.lateMinutes > 0 ? Math.round(row.lateMinutes) : void 0;
	const rowDelayMin = row.delayMinutes != null && Number.isFinite(row.delayMinutes) && row.delayMinutes > 0 ? Math.round(row.delayMinutes) : void 0;
	const synHost = row.cardStatus === "occupied" || row.cardStatus === "barBusy" ? "occupied" : row.cardStatus === "booked" ? "reserved" : void 0;
	return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
		booking_id: `syn_${row.id}`,
		start_date: startD.format("YYYY-MM-DD"),
		start_time: startD.format("HH:mm"),
		end_date: endD.format("YYYY-MM-DD"),
		end_time: endD.format("HH:mm"),
		number: (_row$partySize = row.partySize) !== null && _row$partySize !== void 0 ? _row$partySize : 0
	}, holderFromRow ? { holder: holderFromRow } : {}), {}, {
		amount: amt,
		product_quantity: 0
	}, startsIn != null ? { remainingReserveTime: startsIn } : {}), rowLateMin != null ? { lateTime: rowLateMin } : {}), rowDelayMin != null ? { timeoutTime: rowDelayMin } : {}), synHost ? { hostBookingStatus: synHost } : {}), row.isPaid === true ? { order_payment_status: "paid" } : {}), row.isNext === true ? { isNext: true } : {});
}
function syntheticFromSlot(row, slot, index) {
	var _row$floorMapReferenc2, _row$partySize2;
	const startD = dayjs(`${(_row$floorMapReferenc2 = row.floorMapReferenceDay) !== null && _row$floorMapReferenc2 !== void 0 ? _row$floorMapReferenc2 : dayjs().format("YYYY-MM-DD")} ${slot.time.replace(/ .*/, "").trim() || "12:00"}`);
	const endD = startD.add(2, "hour");
	const sn = slot.name.trim();
	return _objectSpread2(_objectSpread2({
		booking_id: `slot_${index}`,
		start_date: startD.format("YYYY-MM-DD"),
		start_time: startD.format("HH:mm"),
		end_date: endD.format("YYYY-MM-DD"),
		end_time: endD.format("HH:mm"),
		number: (_row$partySize2 = row.partySize) !== null && _row$partySize2 !== void 0 ? _row$partySize2 : 0
	}, sn ? { holder: { name: sn } } : {}), {}, {
		amount: 0,
		product_quantity: 0,
		hostBookingStatus: "reserved"
	});
}
/** 与 merge 一致：宿主 status 大小写不敏感 */
function normalizeHostBookingStatus(b) {
	var _b$status;
	return String((_b$status = b.status) !== null && _b$status !== void 0 ? _b$status : "").trim().toLowerCase();
}
function coerceHostBookingStatusForCard(b) {
	const s = normalizeHostBookingStatus(b);
	if (s === "reserved" || s === "occupied" || s === "locked" || s === "empty") return s;
}
/**
* 原始预约列表里是否存在占用态（决定平面图卡片是否可走占用样式）。
*/
function floorSourceHasOccupiedStatus(list) {
	var _list$some;
	return (_list$some = list === null || list === void 0 ? void 0 : list.some((b) => normalizeHostBookingStatus(b) === "occupied")) !== null && _list$some !== void 0 ? _list$some : false;
}
function floorSourceHasReservedStatus(list) {
	var _list$some2;
	return (_list$some2 = list === null || list === void 0 ? void 0 : list.some((b) => normalizeHostBookingStatus(b) === "reserved")) !== null && _list$some2 !== void 0 ? _list$some2 : false;
}
/**
* 将合并后的桌位行转为 RoomCard 数据：优先使用 {@link PisellReservationTableRow.floorMapSourceBookings} 展示当前时刻下的多条预约时段。
*/
function mapPisellReservationRowToFloorRoomCardData(row, roomTitle) {
	var _row$floorMapSourceBo, _row$slots;
	const cap = row.capacityLabel != null && String(row.capacityLabel).trim() !== "" ? row.capacityLabel : "—";
	const title = roomTitle.trim() || row.code || "";
	if (row.cardStatus === "maintenance") return {
		main_field: title,
		capacity: cap,
		status: "locked",
		sub_status: "",
		bookings: []
	};
	if (row.cardStatus === "available") return {
		main_field: title,
		capacity: cap,
		status: "empty",
		sub_status: "",
		bookings: []
	};
	let bookings = [];
	if ((_row$floorMapSourceBo = row.floorMapSourceBookings) === null || _row$floorMapSourceBo === void 0 ? void 0 : _row$floorMapSourceBo.length) bookings = row.floorMapSourceBookings.map((b, i) => rawToBooking(b, i));
	else if ((_row$slots = row.slots) === null || _row$slots === void 0 ? void 0 : _row$slots.length) bookings = row.slots.map((s, i) => syntheticFromSlot(row, s, i));
	else bookings = [syntheticFromRow(row)];
	const rawFloorSource = row.floorMapSourceBookings;
	/**
	* 有 `floorMapSourceBookings`（当前画布数据，如时间轴选中时刻下 getResourceBookingList 行内 bookings）时：
	* 仅当其中至少一条 `status === occupied` 才展示占用卡片；若全部都不是 occupied，则绝不展示占用肤。
	* 无该列表（slots / 合成行）时仍信 row.cardStatus。
	*/
	let useOccupiedCard = row.cardStatus === "occupied" || row.cardStatus === "barBusy";
	let useBookedCard = row.cardStatus === "booked";
	if (rawFloorSource === null || rawFloorSource === void 0 ? void 0 : rawFloorSource.length) if (floorSourceHasOccupiedStatus(rawFloorSource)) useOccupiedCard = true;
	else {
		useOccupiedCard = false;
		if (floorSourceHasReservedStatus(rawFloorSource)) useBookedCard = true;
	}
	if (useOccupiedCard) {
		let sub = "payed";
		if (row.hostIsTimeout === true || row.delayMinutes != null && row.delayMinutes > 0) sub = "timeout";
		else if (row.isPaid === false) sub = "payment_required";
		else sub = "payed";
		const occupiedBookings = bookings.length > 1 ? reorderBookingsForSingleOccupiedPrimary(bookings) : bookings;
		return {
			main_field: title,
			capacity: cap,
			status: "occupied",
			sub_status: sub,
			bookings: occupiedBookings
		};
	}
	if (useBookedCard) {
		let sub = "not_arrived";
		if (row.hostReservedStatus === "late") sub = "late";
		else if (row.hostReservedStatus === "not_arrived") sub = "not_arrived";
		else if (row.lateMinutes != null && row.lateMinutes > 0) sub = "late";
		const reservedBookings = bookings.length > 1 ? reorderBookingsAllReservedChronological(bookings) : bookings;
		return {
			main_field: title,
			capacity: cap,
			status: "reserved",
			sub_status: sub,
			bookings: reservedBookings
		};
	}
	return {
		main_field: title,
		capacity: cap,
		status: "empty",
		sub_status: "",
		bookings: []
	};
}
/**
* 与 `bookingDetailOrderStripFromRaw` 的 `stripBookingId` 一致：
* `booking_id` → `id` → `order.shop_full_order_number` → `order.order_number`。
*/
function resolveBookingStripIdForUi(raw) {
	var _ref12;
	const order = (_ref12 = raw.order) !== null && _ref12 !== void 0 ? _ref12 : {};
	const pick = (v) => v != null && String(v).trim() !== "" ? String(v).trim() : "";
	return pick(raw.booking_id) || pick(raw.id) || pick(order.shop_full_order_number) || pick(order.order_number) || "—";
}
/**
* 详情弹窗 RoomCard 顶栏：预约标识 `booking_id` → `booking_uid` → `id`，均无则 `—`。
*/
function resolveBookingIdForHeader(raw) {
	const pick = (v) => v != null && String(v).trim() !== "" ? String(v).trim() : "";
	return pick(raw.booking_id) || pick(raw.booking_uid) || pick(raw.id) || "—";
}
/**
* 预约详情弹窗：仅用当前点击的一条 raw 构造 RoomCard（`floorMapSourceBookings` 仅此元素），
* `main_field` 与粉头条同源；弹窗顶栏展示建议再传 {@link resolveBookingIdForHeader} 给 {@link FloorRoomCardFromData}。
*/
function buildDetailModalRoomCardData(raw, tableRow) {
	var _ref13, _ref14, _raw$id;
	return mapPisellReservationRowToFloorRoomCardData(_objectSpread2(_objectSpread2({}, tableRow !== null && tableRow !== void 0 ? tableRow : {
		id: String((_ref13 = (_ref14 = (_raw$id = raw.id) !== null && _raw$id !== void 0 ? _raw$id : raw.booking_uid) !== null && _ref14 !== void 0 ? _ref14 : raw.booking_id) !== null && _ref13 !== void 0 ? _ref13 : "modal-booking"),
		code: (() => {
			const bid = raw.booking_id;
			const rid = raw.id;
			return (bid != null && String(bid).trim() !== "" ? String(bid).trim() : rid != null && String(rid).trim() !== "" ? String(rid).trim() : "") || "—";
		})(),
		cardStatus: "booked"
	}), {}, { floorMapSourceBookings: [raw] }), resolveBookingStripIdForUi(raw));
}
//#endregion
export { buildDetailModalRoomCardData, mapPisellReservationRowToFloorRoomCardData, resolveBookingIdForHeader, resolveBookingStripIdForUi, resolveFloorRoomCardHolder };
