var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/floorRoomCard/buildCardBodyViewModel.ts
var buildCardBodyViewModel_exports = {};
__export(buildCardBodyViewModel_exports, {
  buildRoomCardBodyViewModel: () => buildRoomCardBodyViewModel,
  paymentBadgeClassName: () => paymentBadgeClassName
});
module.exports = __toCommonJS(buildCardBodyViewModel_exports);
var import_utils = require("@pisell/utils");
var import_floorRoomCardDom = require("./floorRoomCardDom");
var import_floorRoomCardPaymentUi = require("./floorRoomCardPaymentUi");
var import_floorRoomCardDiscEdge = require("./floorRoomCardDiscEdge");
var import_floorRoomCardUtils = require("./floorRoomCardUtils");
var I18N_END = "pisell-reservation.room-time-end";
var I18N_START = "pisell-reservation.room-time-start";
var I18N_IN = "pisell-reservation.room-in-minutes";
var I18N_LATE = "pisell-reservation.late";
var I18N_PAID = "pisell-reservation.room-paid";
var I18N_PAYMENT_NEEDED = "pisell-reservation.room-payment-needed";
var I18N_ITEMS_TOTAL = "pisell-reservation.room-items-total";
var I18N_ITEMS_SUMMARY = "pisell-reservation.room-items-summary";
var I18N_DUE_LABEL = "pisell-reservation.booking-detail.strip-due-label";
function i18nArrivalCountdown(totalMin) {
  const d = (0, import_floorRoomCardUtils.formatFloorRoomCardDurationMinutes)(Math.round(totalMin));
  return import_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 _a, _b, _c;
  const { cardType, booking, data, compact } = params;
  const shellShape = params.shellShape ?? "rect";
  const nowMs = params.nowMs ?? Date.now();
  const floorDensity = "comfortable";
  const isReserved = cardType === "not_arrived" || cardType === "late";
  const isOccupied = cardType === "payed" || cardType === "payment_required" || cardType === "timeout";
  const showPhone = isReserved;
  const narrowTimeLabels = floorDensity === "mini" || floorDensity === "micro";
  const startSuffix = narrowTimeLabels ? "" : import_utils.locales.getText(I18N_START);
  const endSuffix = narrowTimeLabels ? "" : import_utils.locales.getText(I18N_END);
  const reservedStartLine = (0, import_floorRoomCardUtils.formatFloorRoomCardBookingStartLine)(
    booking,
    startSuffix
  );
  const reservedEndLine = (0, import_floorRoomCardUtils.formatFloorRoomCardBookingEndLine)(
    booking,
    endSuffix
  );
  const hasReservedEndTime = String(booking.end_time ?? "").trim().length > 0;
  const timeLabel = narrowTimeLabels ? isReserved ? reservedStartLine : (0, import_floorRoomCardUtils.formatFloorRoomCardBookingEndLine)(booking, endSuffix) : isReserved ? !compact && hasReservedEndTime ? `${reservedStartLine} · ${reservedEndLine}` : reservedStartLine : (0, import_floorRoomCardUtils.formatFloorRoomCardBookingEndLine)(booking, import_utils.locales.getText(I18N_END));
  const arrivalMin = compact && isReserved ? (0, import_floorRoomCardUtils.resolveFloorRoomCardReservedCountdownMinutesForBooking)(booking) : (0, import_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 ? (0, import_floorRoomCardUtils.formatFloorRoomCardDurationMinutes)(booking.lateTime) : null;
  const reservedLateOverrun = cardType === "late" && lateDurationLabel ? `${import_utils.locales.getText(I18N_LATE)} +${lateDurationLabel}` : null;
  const timeoutDurationLabel = booking.timeoutTime != null && Number.isFinite(booking.timeoutTime) && booking.timeoutTime > 0 ? (0, import_floorRoomCardUtils.formatFloorRoomCardDurationMinutes)(booking.timeoutTime) : null;
  const occupiedTimeoutOverrun = cardType === "timeout" && timeoutDurationLabel ? `+${timeoutDurationLabel}` : null;
  const paymentKind = (0, import_floorRoomCardPaymentUi.floorRoomCardPaymentUiFromOrderStatus)(
    booking.order_payment_status
  );
  const isTimeout = cardType === "timeout";
  const nextBooking = (0, import_floorRoomCardUtils.resolveFloorRoomCardNextBookingLikeBodyModel)(
    data,
    nowMs
  );
  const holder = booking.holder;
  let guestContactSegments = (0, import_floorRoomCardUtils.floorRoomCardGuestSegments)(booking, showPhone);
  if (floorDensity === "micro" || floorDensity === "mini") {
    guestContactSegments = [];
  }
  const useIntegratedContactSegments = guestContactSegments.length > 0;
  const name = ((_a = holder == null ? void 0 : holder.name) == null ? void 0 : _a.trim()) ?? "";
  const maskedPhone = !useIntegratedContactSegments && showPhone && (holder == null ? void 0 : holder.phone) ? (0, import_floorRoomCardUtils.maskPisellReservationPhoneTail)(holder.phone) : null;
  const guestNameCompact = guestContactSegments.join(
    import_floorRoomCardUtils.FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP
  );
  let nextGuestLine = null;
  let nextGuestContactSegments = [];
  let nextTimeRange = null;
  if (nextBooking) {
    nextGuestContactSegments = (0, import_floorRoomCardUtils.floorRoomCardGuestSegments)(nextBooking, true);
    nextGuestLine = nextGuestContactSegments.length ? nextGuestContactSegments.join(import_floorRoomCardUtils.FLOOR_ROOM_CARD_GUEST_SEGMENT_SEP) : null;
    nextTimeRange = (0, import_floorRoomCardUtils.formatFloorRoomCardBookingTimeRange)(nextBooking);
  }
  const progressPercent = (0, import_floorRoomCardUtils.resolveFloorRoomCardProgressPercent)(booking);
  const orderNumberDisplay = ((_b = booking.order_display_number) == null ? void 0 : _b.trim()) || null;
  const amountPrefixLabel = isOccupied && paymentKind !== "paid" ? import_utils.locales.getText(I18N_DUE_LABEL) : null;
  const productItemCount = booking.product_quantity ?? 0;
  const productTotalQty = booking.product_total_quantity;
  const baseItemsCountLabel = productTotalQty != null && productTotalQty > 0 && productItemCount > 0 ? import_utils.locales.getText(I18N_ITEMS_SUMMARY).replace(/\{items\}/g, String(productItemCount)).replace(/\{qty\}/g, String(productTotalQty)) : import_utils.locales.getText(I18N_ITEMS_TOTAL).replace(/\{n\}/g, String(productItemCount));
  const itemsSummarySuffix = (_c = booking.items_summary_suffix) == null ? void 0 : _c.trim();
  const itemsCountLabel = itemsSummarySuffix ? `${baseItemsCountLabel} · ${itemsSummarySuffix}` : baseItemsCountLabel;
  const showLargeAmountRow = !compact && (isOccupied || isReserved) && floorDensity !== "micro" && floorDensity !== "mini";
  const showInlinePaymentBadge = shellShape === "circle" && isOccupied && !compact;
  const showAmountInlineBadge = !compact && isOccupied && floorDensity === "comfortable" && showInlinePaymentBadge;
  const showPaymentStamp = floorDensity === "comfortable" && !compact && isOccupied && (shellShape === "rect" || !showInlinePaymentBadge);
  const showCompactCommerceRow = compact && isOccupied && floorDensity !== "micro" && floorDensity !== "mini";
  const itemsCountInsideScroll = showCompactCommerceRow;
  const showEdgeProgressRing = import_floorRoomCardDiscEdge.FLOOR_ROOM_CARD_DISC_EDGE_RING_ENABLED && shellShape === "circle" && !compact && isOccupied;
  const showEdgeProgressRectBorder = shellShape === "rect" && !compact && isOccupied && floorDensity !== "comfortable";
  return {
    layout: compact ? "compact" : "full",
    checkoutDomKey: (0, import_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: import_utils.locales.getText(paymentLabelKey(paymentKind)),
    paymentStampText: import_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
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildRoomCardBodyViewModel,
  paymentBadgeClassName
});
