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
});
module.exports = __toCommonJS(buildCardBodyViewModel_exports);
var import_utils = require("@pisell/utils");
var import_floorRoomCardDom = require("./floorRoomCardDom");
var import_floorRoomCardPaymentUi = require("./floorRoomCardPaymentUi");
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";
function i18nArrivalCountdown(totalMin) {
  const d = (0, import_floorRoomCardUtils.formatFloorRoomCardDurationMinutes)(Math.round(totalMin));
  return import_utils.locales.getText(I18N_IN).replace(/\{d\}/g, d);
}
function guestDisplayLine(holder, showPhone) {
  var _a;
  const n = (_a = holder == null ? void 0 : holder.name) == null ? void 0 : _a.trim();
  if (n) return n;
  if (showPhone && (holder == null ? void 0 : holder.phone)) {
    const m = (0, import_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 _a;
  const { cardType, booking, data, compact } = params;
  const shellShape = params.shellShape ?? "rect";
  const nowMs = 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} ${import_utils.locales.getText(I18N_START)}` : `${booking.end_time} ${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.getFloorRoomCardExplicitNextBooking)(data) ?? (0, import_floorRoomCardUtils.getFloorRoomCardNextAfterSingleOccupiedBooking)(data) ?? (0, import_floorRoomCardUtils.getFloorRoomCardNextAfterPrimaryReserved)(data) ?? (0, import_floorRoomCardUtils.getFloorRoomCardNextNotStartedBooking)(data, nowMs);
  const holder = booking.holder;
  const name = ((_a = holder == null ? void 0 : holder.name) == null ? void 0 : _a.trim()) ?? "";
  const maskedPhone = showPhone && (holder == null ? void 0 : holder.phone) ? (0, import_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 = (0, import_floorRoomCardUtils.resolveFloorRoomCardProgressPercent)(booking);
  const productQty = booking.product_quantity ?? 0;
  const itemsCountLabel = import_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);
  const showCompactCommerceRow = compact && isOccupied;
  const itemsCountInsideScroll = showCompactCommerceRow;
  return {
    layout: compact ? "compact" : "full",
    checkoutDomKey: (0, import_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: 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,
    progressPercent,
    progressIsTimeout: isTimeout,
    nextGuestLine,
    nextTimeRange
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  buildRoomCardBodyViewModel
});
