require("../../../_virtual/_rolldown/runtime.js");
const require_floorRoomCardUtils = require("./floorRoomCardUtils.js");
const require_floorRoomCardDom = require("./floorRoomCardDom.js");
const require_floorRoomCardPaymentUi = require("./floorRoomCardPaymentUi.js");
let _pisell_utils = require("@pisell/utils");
//#region src/plus/pisellReservation/floorRoomCard/buildCardBodyViewModel.ts
/**
* 将业务 booking / 卡型 / 布局模式转为 {@link RoomCardBodyView} 所需纯展示字段（含 i18n 解析）。
*/
const I18N_END = "pisell-reservation.room-time-end";
const I18N_START = "pisell-reservation.room-time-start";
const I18N_IN = "pisell-reservation.room-in-minutes";
const I18N_LATE = "pisell-reservation.late";
const I18N_PAID = "pisell-reservation.room-paid";
const I18N_PAYMENT_NEEDED = "pisell-reservation.room-payment-needed";
const I18N_ITEMS_TOTAL = "pisell-reservation.room-items-total";
function i18nArrivalCountdown(totalMin) {
	const d = require_floorRoomCardUtils.formatFloorRoomCardDurationMinutes(Math.round(totalMin));
	return _pisell_utils.locales.getText(I18N_IN).replace(/\{d\}/g, d);
}
function guestDisplayLine(holder, showPhone) {
	var _holder$name;
	const 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 ? void 0 : holder.phone)) {
		const m = require_floorRoomCardUtils.maskPisellReservationPhoneTail(holder.phone);
		if (m) return m;
	}
	return "";
}
function paymentAmountClassName(kind) {
	if (kind === "paid") return "rc-highlight--paid";
	return "rc-highlight--unpaid";
}
function paymentBadgeClassName(kind) {
	if (kind === "paid") return "rc-compact__badge--paid";
	return "rc-compact__badge--unpaid";
}
function paymentLabelKey(kind) {
	if (kind === "paid") return I18N_PAID;
	return I18N_PAYMENT_NEEDED;
}
function buildRoomCardBodyViewModel(params) {
	var _params$shellShape, _params$nowMs, _ref, _ref2, _getFloorRoomCardExpl, _holder$name$trim, _holder$name2, _booking$product_quan;
	const { cardType, booking, data, compact } = params;
	const shellShape = (_params$shellShape = params.shellShape) !== null && _params$shellShape !== void 0 ? _params$shellShape : "rect";
	const nowMs = (_params$nowMs = params.nowMs) !== null && _params$nowMs !== void 0 ? _params$nowMs : Date.now();
	const isReserved = cardType === "not_arrived" || cardType === "late";
	const isOccupied = cardType === "payed" || cardType === "payment_required" || cardType === "timeout";
	const showPhone = isReserved;
	const timeLabel = isReserved ? `${booking.start_time} ${_pisell_utils.locales.getText(I18N_START)}` : `${booking.end_time} ${_pisell_utils.locales.getText(I18N_END)}`;
	const arrivalMin = compact && isReserved ? require_floorRoomCardUtils.resolveFloorRoomCardReservedCountdownMinutesForBooking(booking) : require_floorRoomCardUtils.resolveFloorRoomCardReservedCountdownMinutes(data);
	const countdown = cardType === "not_arrived" && arrivalMin != null && arrivalMin > 0 ? i18nArrivalCountdown(arrivalMin) : null;
	const lateDurationLabel = booking.lateTime != null && Number.isFinite(booking.lateTime) && booking.lateTime > 0 ? require_floorRoomCardUtils.formatFloorRoomCardDurationMinutes(booking.lateTime) : null;
	const reservedLateOverrun = cardType === "late" && lateDurationLabel ? `${_pisell_utils.locales.getText(I18N_LATE)} +${lateDurationLabel}` : null;
	const timeoutDurationLabel = booking.timeoutTime != null && Number.isFinite(booking.timeoutTime) && booking.timeoutTime > 0 ? require_floorRoomCardUtils.formatFloorRoomCardDurationMinutes(booking.timeoutTime) : null;
	const occupiedTimeoutOverrun = cardType === "timeout" && timeoutDurationLabel ? `+${timeoutDurationLabel}` : null;
	const paymentKind = require_floorRoomCardPaymentUi.floorRoomCardPaymentUiFromOrderStatus(booking.order_payment_status);
	const isTimeout = cardType === "timeout";
	const nextBooking = (_ref = (_ref2 = (_getFloorRoomCardExpl = require_floorRoomCardUtils.getFloorRoomCardExplicitNextBooking(data)) !== null && _getFloorRoomCardExpl !== void 0 ? _getFloorRoomCardExpl : require_floorRoomCardUtils.getFloorRoomCardNextAfterSingleOccupiedBooking(data)) !== null && _ref2 !== void 0 ? _ref2 : require_floorRoomCardUtils.getFloorRoomCardNextAfterPrimaryReserved(data)) !== null && _ref !== void 0 ? _ref : require_floorRoomCardUtils.getFloorRoomCardNextNotStartedBooking(data, nowMs);
	const holder = booking.holder;
	const name = (_holder$name$trim = holder === null || holder === void 0 || (_holder$name2 = holder.name) === null || _holder$name2 === void 0 ? void 0 : _holder$name2.trim()) !== null && _holder$name$trim !== void 0 ? _holder$name$trim : "";
	const maskedPhone = showPhone && (holder === null || holder === void 0 ? void 0 : holder.phone) ? require_floorRoomCardUtils.maskPisellReservationPhoneTail(holder.phone) : null;
	const guestNameCompact = guestDisplayLine(booking.holder, showPhone);
	let nextGuestLine = null;
	let nextTimeRange = null;
	if (nextBooking) {
		nextGuestLine = guestDisplayLine(nextBooking.holder, true) || null;
		nextTimeRange = `${nextBooking.start_time} - ${nextBooking.end_time}`;
	}
	const progressPercent = require_floorRoomCardUtils.resolveFloorRoomCardProgressPercent(booking);
	const productQty = (_booking$product_quan = booking.product_quantity) !== null && _booking$product_quan !== void 0 ? _booking$product_quan : 0;
	const itemsCountLabel = _pisell_utils.locales.getText(I18N_ITEMS_TOTAL).replace(/\{n\}/g, String(productQty));
	/** 预约中（预留）：单条/多条均不展示金额、付款、件数 */
	const showLargeAmountRow = !compact && isOccupied;
	const showInlinePaymentBadge = shellShape === "circle" && isOccupied && !compact;
	const showAmountInlineBadge = !compact && shellShape === "circle" && showInlinePaymentBadge;
	/** 方桌单条占用：大圆印章；圆桌单条占用：行内徽章故无印章 */
	const showPaymentStamp = !compact && isOccupied && (shellShape === "rect" || !showInlinePaymentBadge);
	/** 多条 compact：仅占用行展示金额/徽章/件数；件数与时刻同轨 */
	const showCompactCommerceRow = compact && isOccupied;
	const itemsCountInsideScroll = showCompactCommerceRow;
	return {
		layout: compact ? "compact" : "full",
		checkoutDomKey: require_floorRoomCardDom.floorRoomCardBookingCheckoutDomKey(booking),
		cardType,
		contactName: name,
		contactPhoneMasked: maskedPhone,
		showContactPhone: showPhone,
		guestNameCompact,
		timeLabel,
		partySize: booking.number,
		amountDisplay: booking.amount,
		countdown,
		reservedLateOverrun,
		occupiedTimeoutOverrun,
		paymentAmountClass: paymentAmountClassName(paymentKind),
		paymentBadgeClass: paymentBadgeClassName(paymentKind),
		paymentBadgeText: _pisell_utils.locales.getText(paymentLabelKey(paymentKind)),
		paymentStampText: _pisell_utils.locales.getText(paymentLabelKey(paymentKind)),
		paymentIsPaid: paymentKind === "paid",
		paymentStampVariant: paymentKind,
		showLargeAmountRow,
		showProgress: isOccupied,
		showPaymentStamp,
		showInlinePaymentBadge,
		showAmountInlineBadge,
		showCompactCommerceRow,
		itemsCountLabel,
		itemsCountInsideScroll,
		progressPercent,
		progressIsTimeout: isTimeout,
		nextGuestLine,
		nextTimeRange
	};
}
//#endregion
exports.buildRoomCardBodyViewModel = buildRoomCardBodyViewModel;
