import { I18N_HUD_TABLE_DRAWER_TITLE, PISELL_RESERVATION_HUD_DRAWER_COLUMN_STORAGE_KEY } from "../reservationConstants.js";
import { ReservationFloorMapHudTitleBar } from "../floorMap/ReservationFloorMapHud.js";
import ReservationHudDrawerHandle from "../floorMap/ReservationHudDrawerHandle.js";
import React, { useLayoutEffect } from "react";
import { locales } from "@pisell/utils";
import { PisellRecordBoard } from "@pisell/materials";
//#region src/plus/pisellReservation/components/ReservationHudDrawer.tsx
/**
* 读取元素上均匀 scale（matrix(a,0,0,d,...)）；非均匀或无法解析时返回 1。
* body 整体 scale 时 layout×scale≈视觉；要保持「相当于 98vh」的屏幕占比，应用 height: calc(98vh / scale)。
*/
function readUniformScaleFromTransform(el) {
	const t = getComputedStyle(el).transform;
	if (!t || t === "none") return 1;
	try {
		const m = new DOMMatrixReadOnly(t);
		const sx = Math.abs(m.a);
		const sy = Math.abs(m.d);
		if (!Number.isFinite(sx) || !Number.isFinite(sy)) return 1;
		if (Math.abs(sx - sy) > .03) return 1;
		return sx > 1e-6 ? sx : 1;
	} catch (_unused) {
		return 1;
	}
}
/**
* 平面图 HUD：左下角 chip + 展开抽屉（内嵌 RecordBoard + 可选资源竖栏）。
*/
function ReservationHudDrawer({ floorMapHudTableDrawer, showVenueHudDock, hudDrawerOpen, hudDrawerRef, hudMapItems, dataSources, handleOpenHudTableDrawer, closeHudTableDrawer, rowKey, hudDrawerPagedRows, hudDrawerLoading, hudDrawerFilteredTotal, hudDrawerBookingPagination, hudDrawerOnPageChange, hudDrawerLocalSearchParams, hudDrawerOnSearch, hudDrawerOnReset, hudDrawerGrid, hudDrawerToolBar, batchActionBar, hudDrawerResourceRootBuckets, handleHudDrawerFormRecordIdsChange }) {
	/**
	* body 带均匀 scale 时：`98vh` 布局尺寸正确，屏幕上视觉高度会 ×scale；
	* 打开抽屉时用 `calc(98vh / scale)` 对齐「视觉上约 98vh」的占位。
	*/
	useLayoutEffect(() => {
		if (typeof window === "undefined") return;
		if (!hudDrawerOpen) {
			const cleared = hudDrawerRef.current;
			if (cleared) {
				cleared.style.height = "";
				cleared.style.maxHeight = "";
			}
			return;
		}
		const el = hudDrawerRef.current;
		if (!el) return;
		const scale = readUniformScaleFromTransform(document.body);
		if (scale > 0 && Math.abs(scale - 1) > .001) {
			el.style.height = `calc(98vh / ${scale})`;
			el.style.maxHeight = `calc(98vh / ${scale})`;
		} else {
			el.style.height = "";
			el.style.maxHeight = "";
		}
		return () => {
			const next = hudDrawerRef.current;
			if (next) {
				next.style.height = "";
				next.style.maxHeight = "";
			}
		};
	}, [hudDrawerOpen, hudDrawerRef]);
	if (!showVenueHudDock) return null;
	return /* @__PURE__ */ React.createElement(React.Fragment, null, !hudDrawerOpen ? /* @__PURE__ */ React.createElement("div", {
		className: "pisell-reservation-hud-title",
		role: "button",
		tabIndex: 0,
		"aria-label": locales.getText(I18N_HUD_TABLE_DRAWER_TITLE),
		onClick: handleOpenHudTableDrawer,
		onKeyDown: (e) => {
			if (e.key === "Enter" || e.key === " ") {
				e.preventDefault();
				handleOpenHudTableDrawer();
			}
		}
	}, /* @__PURE__ */ React.createElement(ReservationFloorMapHudTitleBar, {
		items: hudMapItems,
		dataSources,
		actionMode: "expand",
		onAction: handleOpenHudTableDrawer,
		embedded: true,
		className: "pisell-reservation-hud-title-inner"
	})) : null, hudDrawerOpen ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
		className: "pisell-reservation-hud-drawer-mask",
		onClick: closeHudTableDrawer,
		"aria-hidden": "true"
	}), /* @__PURE__ */ React.createElement("div", {
		className: "pisell-reservation-hud-drawer",
		role: "dialog",
		"aria-modal": "false",
		"aria-label": locales.getText(I18N_HUD_TABLE_DRAWER_TITLE),
		ref: hudDrawerRef
	}, /* @__PURE__ */ React.createElement(ReservationHudDrawerHandle, {
		onClose: closeHudTableDrawer,
		drawerRef: hudDrawerRef
	}), /* @__PURE__ */ React.createElement("div", { className: "pisell-reservation-hud-drawer-record-board" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-reservation-hud-drawer-split" }, /* @__PURE__ */ React.createElement("div", { className: "pisell-reservation-hud-drawer-split-main" }, /* @__PURE__ */ React.createElement(PisellRecordBoard, {
		layoutVariant: "phone",
		columnVisibilityStorageKey: PISELL_RESERVATION_HUD_DRAWER_COLUMN_STORAGE_KEY,
		rowKey,
		data: hudDrawerPagedRows,
		loading: hudDrawerLoading,
		total: hudDrawerFilteredTotal,
		pagination: hudDrawerBookingPagination,
		onPageChange: hudDrawerOnPageChange,
		searchParams: hudDrawerLocalSearchParams,
		onSearch: hudDrawerOnSearch,
		onReset: hudDrawerOnReset,
		grid: hudDrawerGrid,
		toolBar: hudDrawerToolBar,
		batchActionBar,
		defaultBodyView: "grid",
		bodyViewSwitchable: false,
		lockedBodyView: "grid"
	}, /* @__PURE__ */ React.createElement(PisellRecordBoard.ShellFrame, { belowToolbar: void 0 }, /* @__PURE__ */ React.createElement(PisellRecordBoard.GridLayout, null)))), null)))) : null);
}
//#endregion
export { ReservationHudDrawer };
