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";
const I18N_ITEMS_SUMMARY = "pisell-reservation.room-items-summary";
const I18N_DUE_LABEL = "pisell-reservation.booking-detail.strip-due-label";
function i18nArrivalCountdown(totalMin) {
	const d = require_floorRoomCardUtils.formatFloorRoomCardDurationMinutes(Math.round(totalMin));
	return _pisell_utils.locales.getText(I18N_IN).replace(/\{d\}/g, d);
}
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, _booking$end_time, _holder$name$trim, _holder$name, _booking$order_displa, _booking$product_quan, _booking$items_summar;
	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();
	/** 与大卡 {@link RoomCardBodyView} 一致：不保留测量档 mini/micro/compact 的异化正文 */
	const floorDensity = "comfortable";
	const isReserved = cardType === "not_arrived" || cardType === "late";
	const isOccupied = cardType === "payed" || cardType === "payment_required" || cardType === "timeout";
	const showPhone = isReserved;
	/** mini/micro：不拼接「开始/结束」后缀；预约态只显示开始时刻，占用态只显示结束时刻 */
	const narrowTimeLabels = floorDensity === "mini" || floorDensity === "micro";
	const startSuffix = narrowTimeLabels ? "" : _pisell_utils.locales.getText(I18N_START);
	const endSuffix = narrowTimeLabels ? "" : _pisell_utils.locales.getText(I18N_END);
	const reservedStartLine = require_floorRoomCardUtils.formatFloorRoomCardBookingStartLine(booking, startSuffix);
	const reservedEndLine = require_floorRoomCardUtils.formatFloorRoomCardBookingEndLine(booking, endSuffix);
	const hasReservedEndTime = String((_booking$end_time = booking.end_time) !== null && _booking$end_time !== void 0 ? _booking$end_time : "").trim().length > 0;
	/** 详情（非 compact）且尚未到店/迟到预留：展示起止；平面图紧凑格仅展示开始 */
	const timeLabel = narrowTimeLabels ? isReserved ? reservedStartLine : require_floorRoomCardUtils.formatFloorRoomCardBookingEndLine(booking, endSuffix) : isReserved ? !compact && hasReservedEndTime ? `${reservedStartLine} · ${reservedEndLine}` : reservedStartLine : require_floorRoomCardUtils.formatFloorRoomCardBookingEndLine(booking, _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 = require_floorRoomCardUtils.resolveFloorRoomCardNextBookingLikeBodyModel(data, nowMs);
	const holder = booking.holder;
	let guestContactSegments = require_floorRoomCardUtils.floorRoomCardGuestSegments(booking, showPhone);
	/** mini/micro：正文人展示极简层，不带来联系人分段 */
	if (floorDensity === "micro" || floorDensity === "mini") guestContactSegments = [];
	/** 分段展示合并进各层后，不再单独重复尾号行 */
	const useIntegratedContactSegments = guestContactSegments.length > 0;
	const name = (_holder$name$trim = holder === null || holder === void 0 || (_holder$name = holder.name) === null || _holder$name === void 0 ? void 0 : _holder$name.trim()) !== null && _holder$name$trim !== void 0 ? _holder$name$trim : "";
	const maskedPhone = !useIntegratedContactSegments && showPhone && (holder === null || holder === void 0 ? void 0 : holder.phone) ? require_floorRoomCardUtils.maskPisellReservationPhoneTail(holder.phone) : null;
	const guestNameCompact = guestContactSegments.join(require_floorRoomCardUtils.FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP);
	let nextGuestLine = null;
	let nextGuestContactSegments = [];
	let nextTimeRange = null;
	if (nextBooking) {
		nextGuestContactSegments = require_floorRoomCardUtils.floorRoomCardGuestSegments(nextBooking, true);
		nextGuestLine = nextGuestContactSegments.length ? nextGuestContactSegments.join(require_floorRoomCardUtils.FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP) : null;
		nextTimeRange = require_floorRoomCardUtils.formatFloorRoomCardBookingTimeRange(nextBooking);
	}
	const progressPercent = require_floorRoomCardUtils.resolveFloorRoomCardProgressPercent(booking);
	const orderNumberDisplay = ((_booking$order_displa = booking.order_display_number) === null || _booking$order_displa === void 0 ? void 0 : _booking$order_displa.trim()) || null;
	const amountPrefixLabel = isOccupied && paymentKind !== "paid" ? _pisell_utils.locales.getText(I18N_DUE_LABEL) : null;
	const productItemCount = (_booking$product_quan = booking.product_quantity) !== null && _booking$product_quan !== void 0 ? _booking$product_quan : 0;
	const productTotalQty = booking.product_total_quantity;
	const baseItemsCountLabel = productTotalQty != null && productTotalQty > 0 && productItemCount > 0 ? _pisell_utils.locales.getText(I18N_ITEMS_SUMMARY).replace(/\{items\}/g, String(productItemCount)).replace(/\{qty\}/g, String(productTotalQty)) : _pisell_utils.locales.getText(I18N_ITEMS_TOTAL).replace(/\{n\}/g, String(productItemCount));
	const itemsSummarySuffix = (_booking$items_summar = booking.items_summary_suffix) === null || _booking$items_summar === void 0 ? void 0 : _booking$items_summar.trim();
	const itemsCountLabel = itemsSummarySuffix ? `${baseItemsCountLabel} · ${itemsSummarySuffix}` : baseItemsCountLabel;
	/** 详情卡金额/商品汇总：预约中与占用中都展示；mini/micro 不展示金额行 */
	const showLargeAmountRow = !compact && (isOccupied || isReserved) && floorDensity !== "micro" && floorDensity !== "mini";
	const showInlinePaymentBadge = shellShape === "circle" && isOccupied && !compact;
	/** 金额行旁支付徽标/chip：仅 comfortable；compact/mini/micro 不再展示 */
	const showAmountInlineBadge = !compact && isOccupied && floorDensity === "comfortable" && showInlinePaymentBadge;
	/** 方桌单条占用：大圆印章；圆桌 comfortable：行内徽章故无印章 */
	const showPaymentStamp = floorDensity === "comfortable" && !compact && isOccupied && (shellShape === "rect" || !showInlinePaymentBadge);
	/** 多条 compact：占用行展示金额等；mini/micro 隐藏商务列 */
	const showCompactCommerceRow = compact && isOccupied && floorDensity !== "micro" && floorDensity !== "mini";
	const itemsCountInsideScroll = showCompactCommerceRow;
	const showEdgeProgressRing = shellShape === "circle" && !compact && isOccupied;
	const showEdgeProgressRectBorder = shellShape === "rect" && !compact && isOccupied && floorDensity !== "comfortable";
	return {
		layout: compact ? "compact" : "full",
		checkoutDomKey: require_floorRoomCardDom.floorRoomCardBookingCheckoutDomKey(booking),
		cardType,
		contactName: name,
		contactPhoneMasked: maskedPhone,
		showContactPhone: showPhone,
		guestContactSegments,
		guestNameCompact,
		timeLabel,
		partySize: booking.number,
		amountDisplay: booking.amount,
		orderNumberDisplay,
		amountPrefixLabel,
		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,
		showEdgeProgressRing,
		showEdgeProgressRectBorder,
		progressPercent,
		progressIsTimeout: isTimeout,
		nextGuestLine,
		nextGuestContactSegments,
		nextTimeRange
	};
}
//#endregion
exports.buildRoomCardBodyViewModel = buildRoomCardBodyViewModel;
exports.paymentBadgeClassName = paymentBadgeClassName;
