const require_runtime = require("../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_floorRoomCardUtils = require("../floorRoomCardUtils.js");
const require_floorRoomCardPaymentUi = require("../floorRoomCardPaymentUi.js");
const require_buildCardBodyViewModel = require("../buildCardBodyViewModel.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
//#region src/plus/pisellReservation/floorRoomCard/views/RoomCardTooltipTimeLayout.tsx
/**
* 非 comfortable 极简态：独立 DOM（`.rc-tooltip-time-root`），不使用 `.rc-body` / `.rc-progress`。
* 时间用 antd `Tooltip` 的 `title` 挂在桌名上，`open` 常驻以保持原先「始终可见」的小卡信息密度。
*/
const I18N_PAID = "pisell-reservation.room-paid";
const I18N_PAYMENT_NEEDED = "pisell-reservation.room-payment-needed";
const I18N_START = "pisell-reservation.room-time-start";
const I18N_END = "pisell-reservation.room-time-end";
function extractHmFromTimeField(raw) {
	const s = String(raw !== null && raw !== void 0 ? 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;
	return `${baseTitle} (${typeof source.completeBookingCount === "number" && Number.isFinite(source.completeBookingCount) && source.completeBookingCount >= 0 ? source.completeBookingCount : 0}/${total})`;
}
function TooltipTimeProgressBar(props) {
	const raw = Number(props.percent);
	const clamped = Math.min(100, Math.max(0, Number.isFinite(raw) ? raw : 0));
	return /* @__PURE__ */ react.default.createElement("div", {
		className: "rc-tooltip-time-bar",
		"aria-hidden": true
	}, /* @__PURE__ */ react.default.createElement("div", { className: "rc-tooltip-time-bar__track" }, /* @__PURE__ */ react.default.createElement("div", {
		className: (0, classnames.default)("rc-tooltip-time-bar__fill", props.isTimeout && "rc-tooltip-time-bar__fill--warn"),
		style: { width: `${clamped}%` }
	})));
}
function RoomCardTooltipTimeLayout(props) {
	var _data$main_field;
	const { data, booking, cardType, shellShape = "rect", hideInnerLinearProgress = false, headerMainFieldOverride, scrollSurfaceHandlers } = props;
	/**
	* 小卡标题溢出场景下，直接把 `(N/M)` 拼到字符串末尾即可：tooltip-time 路径
	* 的 `--overflow` 修饰已允许文本越出卡片边界整体展示，不会因卡宽不够而被裁。
	* N = `completeBookingCount ?? 0`，M = `bookingCount`；仅 M > 0 时拼接。
	*/
	const title = appendBookingCountSuffix((headerMainFieldOverride === null || headerMainFieldOverride === void 0 ? void 0 : headerMainFieldOverride.trim()) || String((_data$main_field = data.main_field) !== null && _data$main_field !== void 0 ? _data$main_field : "").trim(), data);
	const isOccupied = cardType === "payed" || cardType === "payment_required" || cardType === "timeout";
	const timeHm = (isOccupied ? extractHmFromTimeField(booking.end_time) || extractHmFromTimeField(booking.start_time) : extractHmFromTimeField(booking.start_time)) || "—";
	const progressPercent = require_floorRoomCardUtils.resolveFloorRoomCardProgressPercent(booking);
	const isTimeout = cardType === "timeout";
	const showLinearProgress = isOccupied && !hideInnerLinearProgress && !(shellShape === "circle" && true);
	const paymentKind = require_floorRoomCardPaymentUi.floorRoomCardPaymentUiFromOrderStatus(booking.order_payment_status);
	const paymentBadgeClass = require_buildCardBodyViewModel.paymentBadgeClassName(paymentKind);
	const paymentText = _pisell_utils.locales.getText(paymentKind === "paid" ? I18N_PAID : I18N_PAYMENT_NEEDED);
	const tooltipBg = "#000000";
	const timeTooltipText = `${timeHm} ${_pisell_utils.locales.getText(isOccupied ? I18N_END : I18N_START)}`;
	return /* @__PURE__ */ react.default.createElement("div", require_objectSpread2._objectSpread2({
		className: "rc-tooltip-time-root",
		"data-pisell-floor-room-scroll-surface": ""
	}, scrollSurfaceHandlers), /* @__PURE__ */ react.default.createElement("div", { className: "rc-tooltip-time-stack" }, isOccupied && paymentKind === "unpaid" ? /* @__PURE__ */ react.default.createElement("span", {
		className: (0, classnames.default)("rc-tooltip-time-pay-badge", "rc-compact__badge", paymentBadgeClass),
		"aria-hidden": true
	}, paymentText) : null, showLinearProgress ? /* @__PURE__ */ react.default.createElement("div", { className: "rc-tooltip-time-progress" }, /* @__PURE__ */ react.default.createElement(TooltipTimeProgressBar, {
		percent: progressPercent,
		isTimeout
	})) : null, /* @__PURE__ */ react.default.createElement("div", { className: "rc-tooltip-time-title-anchor rc-tooltip-time-title-anchor--overflow" }, /* @__PURE__ */ react.default.createElement(antd.Tooltip, {
		title: timeTooltipText,
		placement: "bottom",
		open: true,
		color: tooltipBg,
		autoAdjustOverflow: false,
		getPopupContainer: (node) => {
			var _ref, _node$closest;
			return (_ref = (_node$closest = node.closest(".pisell-res-floor-room-card__viewport-compensate")) !== null && _node$closest !== void 0 ? _node$closest : node.closest(".pisell-res-floor-room-card")) !== null && _ref !== void 0 ? _ref : document.body;
		},
		overlayClassName: (0, classnames.default)("rc-tooltip-time-ant-overlay", !isOccupied && "rc-tooltip-time-ant-overlay--reserved"),
		arrow: true
	}, /* @__PURE__ */ react.default.createElement("span", { className: "rc-tooltip-time-title rc-tooltip-time-title--overflow" }, title)))));
}
/**
* 空态小卡（方桌 / 圆桌共用）：只有桌名、无时间。
*
* 与 {@link RoomCardTooltipTimeLayout} 共用 `rc-tooltip-time-*` DOM 结构，但额外加
* `--title-only` 修饰类：让 `.rc-tooltip-time-title` 取消 ellipsis 裁切，并允许文本
* 以 anchor 中心为参考向左右**溢出**卡片宽度（卡内仍以居中点为锚，不挤占周围卡片排版）。
*
* 该卡片祖先链上的 `data-tooltip-time='on'` 已把 `pisell-res-floor-room-card`、
* `__viewport-compensate`、`.rc--tooltip-time`、`.rc-tooltip-time-main` 等全部设为
* `overflow: visible`，因此 title 文本可直接突破小卡边框显示。
*/
function RoomCardTooltipTitleOnlyLayout(props) {
	var _data$main_field2;
	const { data, headerMainFieldOverride, scrollSurfaceHandlers } = props;
	const titleSafe = appendBookingCountSuffix((headerMainFieldOverride === null || headerMainFieldOverride === void 0 ? void 0 : headerMainFieldOverride.trim()) || String((_data$main_field2 = data.main_field) !== null && _data$main_field2 !== void 0 ? _data$main_field2 : "").trim(), data) || "—";
	return /* @__PURE__ */ react.default.createElement("div", require_objectSpread2._objectSpread2({
		className: "rc-tooltip-time-root",
		"data-pisell-floor-room-scroll-surface": ""
	}, scrollSurfaceHandlers), /* @__PURE__ */ react.default.createElement("div", { className: "rc-tooltip-time-stack rc-tooltip-time-stack--title-only" }, /* @__PURE__ */ react.default.createElement("div", { className: "rc-tooltip-time-title-anchor rc-tooltip-time-title-anchor--overflow" }, /* @__PURE__ */ react.default.createElement("span", { className: "rc-tooltip-time-title rc-tooltip-time-title--overflow" }, titleSafe))));
}
//#endregion
exports.RoomCardTooltipTimeLayout = RoomCardTooltipTimeLayout;
exports.RoomCardTooltipTitleOnlyLayout = RoomCardTooltipTitleOnlyLayout;
exports.appendBookingCountSuffix = appendBookingCountSuffix;
