var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/floorRoomCard/views/RoomCardTooltipTimeLayout.tsx
var RoomCardTooltipTimeLayout_exports = {};
__export(RoomCardTooltipTimeLayout_exports, {
  RoomCardTooltipTimeLayout: () => RoomCardTooltipTimeLayout,
  RoomCardTooltipTitleOnlyLayout: () => RoomCardTooltipTitleOnlyLayout,
  appendBookingCountSuffix: () => appendBookingCountSuffix
});
module.exports = __toCommonJS(RoomCardTooltipTimeLayout_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_floorRoomCardDiscEdge = require("../floorRoomCardDiscEdge");
var import_buildCardBodyViewModel = require("../buildCardBodyViewModel");
var import_floorRoomCardUtils = require("../floorRoomCardUtils");
var import_floorRoomCardPaymentUi = require("../floorRoomCardPaymentUi");
var I18N_PAID = "pisell-reservation.room-paid";
var I18N_PAYMENT_NEEDED = "pisell-reservation.room-payment-needed";
var I18N_START = "pisell-reservation.room-time-start";
var I18N_END = "pisell-reservation.room-time-end";
function extractHmFromTimeField(raw) {
  const s = String(raw ?? "").trim();
  if (!s) return "";
  const parts = s.split(":");
  if (parts.length >= 2) {
    const h = parseInt(parts[0], 10);
    const minDigits = parts[1].replace(/\D/g, "").slice(0, 2);
    const mm = minDigits.length >= 2 ? minDigits.padStart(2, "0") : `${minDigits}0`.slice(0, 2);
    if (Number.isFinite(h)) return `${h}:${mm}`;
  }
  return s;
}
function appendBookingCountSuffix(baseTitle, source) {
  const total = source.bookingCount;
  if (typeof total !== "number" || !Number.isFinite(total) || total <= 0) {
    return baseTitle;
  }
  const complete = typeof source.completeBookingCount === "number" && Number.isFinite(source.completeBookingCount) && source.completeBookingCount >= 0 ? source.completeBookingCount : 0;
  return `${baseTitle} (${complete}/${total})`;
}
function TooltipTimeProgressBar(props) {
  const raw = Number(props.percent);
  const safe = Number.isFinite(raw) ? raw : 0;
  const clamped = Math.min(100, Math.max(0, safe));
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-bar", "aria-hidden": true }, /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-bar__track" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        "rc-tooltip-time-bar__fill",
        props.isTimeout && "rc-tooltip-time-bar__fill--warn"
      ),
      style: { width: `${clamped}%` }
    }
  )));
}
function RoomCardTooltipTimeLayout(props) {
  const {
    data,
    booking,
    cardType,
    shellShape = "rect",
    hideInnerLinearProgress = false,
    headerMainFieldOverride,
    scrollSurfaceHandlers
  } = props;
  const baseTitle = (headerMainFieldOverride == null ? void 0 : headerMainFieldOverride.trim()) || String(data.main_field ?? "").trim();
  const title = appendBookingCountSuffix(baseTitle, data);
  const isOccupied = cardType === "payed" || cardType === "payment_required" || cardType === "timeout";
  const timeHmRaw = isOccupied ? extractHmFromTimeField(booking.end_time) || extractHmFromTimeField(booking.start_time) : extractHmFromTimeField(booking.start_time);
  const timeHm = timeHmRaw || "—";
  const progressPercent = (0, import_floorRoomCardUtils.resolveFloorRoomCardProgressPercent)(booking);
  const isTimeout = cardType === "timeout";
  const showLinearProgress = isOccupied && !hideInnerLinearProgress && !(shellShape === "circle" && import_floorRoomCardDiscEdge.FLOOR_ROOM_CARD_DISC_EDGE_RING_ENABLED);
  const paymentKind = (0, import_floorRoomCardPaymentUi.floorRoomCardPaymentUiFromOrderStatus)(
    booking.order_payment_status
  );
  const paymentBadgeClass = (0, import_buildCardBodyViewModel.paymentBadgeClassName)(paymentKind);
  const paymentText = import_utils.locales.getText(
    paymentKind === "paid" ? I18N_PAID : I18N_PAYMENT_NEEDED
  );
  const tooltipBg = "#000000";
  const timeHintSuffix = import_utils.locales.getText(isOccupied ? I18N_END : I18N_START);
  const timeTooltipText = `${timeHm} ${timeHintSuffix}`;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "rc-tooltip-time-root",
      "data-pisell-floor-room-scroll-surface": "",
      ...scrollSurfaceHandlers
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-stack" }, isOccupied && paymentKind === "unpaid" ? /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: (0, import_classnames.default)(
          "rc-tooltip-time-pay-badge",
          "rc-compact__badge",
          paymentBadgeClass
        ),
        "aria-hidden": true
      },
      paymentText
    ) : null, showLinearProgress ? /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-progress" }, /* @__PURE__ */ import_react.default.createElement(TooltipTimeProgressBar, { percent: progressPercent, isTimeout })) : null, /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-title-anchor rc-tooltip-time-title-anchor--overflow" }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Tooltip,
      {
        title: timeTooltipText,
        placement: "bottom",
        open: true,
        color: tooltipBg,
        autoAdjustOverflow: false,
        getPopupContainer: (node) => (
          /**
           * tooltip 必须挂到会被 viewportScale 缩放的容器里（__viewport-compensate），
           * 否则浮层字体/尺寸不会随图元一起缩放。
           */
          node.closest(".pisell-res-floor-room-card__viewport-compensate") ?? node.closest(".pisell-res-floor-room-card") ?? document.body
        ),
        overlayClassName: (0, import_classnames.default)(
          "rc-tooltip-time-ant-overlay",
          !isOccupied && "rc-tooltip-time-ant-overlay--reserved"
        ),
        arrow: true
      },
      /* @__PURE__ */ import_react.default.createElement("span", { className: "rc-tooltip-time-title rc-tooltip-time-title--overflow" }, title)
    )))
  );
}
function RoomCardTooltipTitleOnlyLayout(props) {
  const { data, headerMainFieldOverride, scrollSurfaceHandlers } = props;
  const baseTitle = (headerMainFieldOverride == null ? void 0 : headerMainFieldOverride.trim()) || String(data.main_field ?? "").trim();
  const titleWithCount = appendBookingCountSuffix(baseTitle, data);
  const titleSafe = titleWithCount || "—";
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "rc-tooltip-time-root",
      "data-pisell-floor-room-scroll-surface": "",
      ...scrollSurfaceHandlers
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-stack rc-tooltip-time-stack--title-only" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "rc-tooltip-time-title-anchor rc-tooltip-time-title-anchor--overflow" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "rc-tooltip-time-title rc-tooltip-time-title--overflow" }, titleSafe)))
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  RoomCardTooltipTimeLayout,
  RoomCardTooltipTitleOnlyLayout,
  appendBookingCountSuffix
});
