import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { getFloorRoomCardPrimaryBooking, getFloorRoomCardType, resolveFloorRoomCardProgressPercent } from "./floorRoomCardUtils.js";
import { FloorRoomCardDensityContext, isFloorRoomCardTooltipDensity, toFloorRoomCardUiDensity, useResolvedFloorRoomCardDensity } from "./floorRoomCardDensity.js";
import { FloorRoomCardFromData } from "./FloorRoomCardFromData.js";
import { RoomCardDiscEdgeProgress } from "./views/RoomCardDiscEdgeProgress.js";
import { RoomCardRectEdgeProgress } from "./views/RoomCardRectEdgeProgress.js";
import React, { useEffect, useMemo, useReducer, useRef } from "react";
//#region src/plus/pisellReservation/floorRoomCard/ReservationFloorRoomCard.tsx
/** 圆桌单条占用外缘环：与 buildCardBodyViewModel.showEdgeProgressRing 条件一致 */
function resolveCircleSingleOccupiedDiscEdgeProgress(data) {
	const t = getFloorRoomCardType(data);
	if (t !== "payed" && t !== "payment_required" && t !== "timeout") return null;
	const booking = getFloorRoomCardPrimaryBooking(data);
	if (!booking) return null;
	return {
		percent: resolveFloorRoomCardProgressPercent(booking),
		isTimeout: t === "timeout"
	};
}
function resolveRectSingleOccupiedEdgeProgress(data) {
	const t = getFloorRoomCardType(data);
	if (t !== "payed" && t !== "payment_required" && t !== "timeout") return null;
	const booking = getFloorRoomCardPrimaryBooking(data);
	if (!booking) return null;
	return {
		percent: resolveFloorRoomCardProgressPercent(booking),
		isTimeout: t === "timeout"
	};
}
/**
* 平面图绑定桌位：RoomCard 视觉（demo 样式）+ 业务行映射数据。
* 内层为 {@link FloorRoomCardFromData}；本组件仅外包根节点并每分钟触发重绘以刷新倒计时/进度。
*
* **视觉大卡 vs Tooltip 小卡**：根节点 `data-density` 仅 comfortable / micro；
* **方桌**仅测量档 **micro** 为小卡壳；**圆桌** **mini / micro** 为小卡壳。正文仍用解析档区分 mini/micro。
*/
function ReservationFloorRoomCard(props) {
	var _data$bookings$length, _data$bookings, _data$bookings$length2, _data$bookings2;
	const { data, theme = "default", shellShape = "rect", elementLayoutHeightPx, hideHeaderCapacity = false, density = "auto", viewportScale = 1, discUnifiedLayoutEnabled = true, tooltipTimeDensityEnabled = true } = props;
	const rootRef = useRef(null);
	/** 含 Next，bookings 长度 >1 即按多条卡：强制大卡密度与缩放策略 */
	const isMultiCard = ((_data$bookings$length = (_data$bookings = data.bookings) === null || _data$bookings === void 0 ? void 0 : _data$bookings.length) !== null && _data$bookings$length !== void 0 ? _data$bookings$length : 0) > 1;
	const autoResolvedDensity = useResolvedFloorRoomCardDensity({
		rootRef,
		density,
		viewportScale
	});
	/** 内层组件用解析档（含 mini/micro），以便正文窄屏分支与 buildModel 一致 */
	const resolvedDensity = useMemo(() => {
		if (isMultiCard) return "comfortable";
		return density === "auto" ? autoResolvedDensity : density;
	}, [
		isMultiCard,
		density,
		autoResolvedDensity
	]);
	/** 根节点 data-density：方桌仅 micro 为小卡壳；圆桌 mini/micro 为小卡壳 */
	const uiDensity = useMemo(() => toFloorRoomCardUiDensity(resolvedDensity, shellShape), [resolvedDensity, shellShape]);
	const shapeData = shellShape === "circle" ? { "data-shape": "circle" } : {};
	const discEdgeProgress = shellShape === "circle" ? resolveCircleSingleOccupiedDiscEdgeProgress(data) : null;
	const rootCardType = getFloorRoomCardType(data);
	const reservedHaloEnabled = rootCardType === "not_arrived" || rootCardType === "late" || rootCardType === "multi_reserved";
	const rectEdgeProgress = shellShape === "rect" && isFloorRoomCardTooltipDensity(resolvedDensity, shellShape) && ((_data$bookings$length2 = (_data$bookings2 = data.bookings) === null || _data$bookings2 === void 0 ? void 0 : _data$bookings2.length) !== null && _data$bookings$length2 !== void 0 ? _data$bookings$length2 : 0) === 1 ? resolveRectSingleOccupiedEdgeProgress(data) : null;
	/** 传入内层的是 min(scale,1)；与 scale(1/vs) + 小布局盒配合，只在缩小时放大图元绘制以抵消 zoom */
	const viewportCompensateScale = isMultiCard ? 1 : Math.min(Number.isFinite(viewportScale) && viewportScale > 0 ? viewportScale : 1, 1);
	const [, bumpLayoutTick] = useReducer((x) => x + 1, 0);
	useEffect(() => {
		const id = window.setInterval(() => {
			bumpLayoutTick();
		}, 6e4);
		return () => window.clearInterval(id);
	}, []);
	return /* @__PURE__ */ React.createElement("div", _objectSpread2({
		ref: rootRef,
		className: "pisell-res-floor-room-card",
		"data-theme": theme === "default" ? void 0 : theme,
		"data-density": uiDensity,
		"data-disc-layout": discUnifiedLayoutEnabled ? "unified" : "legacy",
		"data-tooltip-time": tooltipTimeDensityEnabled && isFloorRoomCardTooltipDensity(resolvedDensity, shellShape) ? "on" : "off",
		"data-reserved-halo": reservedHaloEnabled ? "on" : "off",
		"data-rect-edge-progress": rectEdgeProgress ? "on" : "off",
		style: { ["--floor-card-vs"]: String(viewportCompensateScale) }
	}, shapeData), /* @__PURE__ */ React.createElement(FloorRoomCardDensityContext.Provider, { value: resolvedDensity }, /* @__PURE__ */ React.createElement("div", { className: "pisell-res-floor-room-card__viewport-compensate" }, /* @__PURE__ */ React.createElement(FloorRoomCardFromData, {
		data,
		shellShape,
		elementLayoutHeightPx,
		hideHeaderCapacity,
		discUnifiedLayoutEnabled,
		tooltipTimeDensityEnabled
	}), discEdgeProgress ? /* @__PURE__ */ React.createElement(RoomCardDiscEdgeProgress, {
		percent: discEdgeProgress.percent,
		isTimeout: discEdgeProgress.isTimeout
	}) : null, rectEdgeProgress ? /* @__PURE__ */ React.createElement(RoomCardRectEdgeProgress, {
		percent: rectEdgeProgress.percent,
		isTimeout: rectEdgeProgress.isTimeout
	}) : null)));
}
//#endregion
export { ReservationFloorRoomCard };
