const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_hooks = require("./hooks.js");
const require_context = require("./context.js");
const require_index = require("./components/Content/index.js");
const require_locales = require("./locales.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/venueBooking/index.tsx
/**
* venueBooking 入口组件
* 初始化国际化、标准化入口上下文，并挂载 Provider + Content
*/
function getViewportHeight() {
	var _window$visualViewpor;
	if (typeof window === "undefined") return void 0;
	const visualViewportHeight = (_window$visualViewpor = window.visualViewport) === null || _window$visualViewpor === void 0 ? void 0 : _window$visualViewpor.height;
	if (visualViewportHeight && visualViewportHeight > 0) return Math.round(visualViewportHeight);
	if (window.innerHeight > 0) return window.innerHeight;
}
function getViewportHeightFallback() {
	var _CSS$supports, _CSS, _CSS$supports2, _CSS2;
	if (typeof CSS !== "undefined" && ((_CSS$supports = (_CSS = CSS).supports) === null || _CSS$supports === void 0 ? void 0 : _CSS$supports.call(_CSS, "height", "100dvh"))) return "100dvh";
	if (typeof CSS !== "undefined" && ((_CSS$supports2 = (_CSS2 = CSS).supports) === null || _CSS$supports2 === void 0 ? void 0 : _CSS$supports2.call(_CSS2, "height", "100svh"))) return "100svh";
	return "100%";
}
function getIsMobileFooterVisible() {
	if (typeof window === "undefined") return false;
	return window.matchMedia("(max-width: 1023.98px)").matches;
}
function getViewportStyle(viewportHeight) {
	if (viewportHeight === void 0) {
		const fallbackHeight = getViewportHeightFallback();
		return {
			height: fallbackHeight,
			minHeight: fallbackHeight
		};
	}
	return {
		"--vb-viewport-height": `${viewportHeight}px`,
		height: "var(--vb-viewport-height)",
		minHeight: "var(--vb-viewport-height)"
	};
}
/** 场地预订主组件 */
function VenueBooking(props) {
	var _context$engine, _context$engine2;
	const context = require_useEngineContext.default();
	const entryContext = require_hooks.normalizeEntryContext(context === null || context === void 0 || (_context$engine = context.engine) === null || _context$engine === void 0 ? void 0 : _context$engine.props);
	_pisell_utils.locales.init(require_locales.default, (context === null || context === void 0 || (_context$engine2 = context.engine) === null || _context$engine2 === void 0 || (_context$engine2 = _context$engine2.props) === null || _context$engine2 === void 0 ? void 0 : _context$engine2.locale) || "en");
	const [viewportHeight, setViewportHeight] = (0, react.useState)(getViewportHeight);
	const [isMobileFooterVisible, setIsMobileFooterVisible] = (0, react.useState)(getIsMobileFooterVisible);
	(0, react.useEffect)(() => {
		var _window$visualViewpor2, _window$visualViewpor3;
		let frameId;
		function updateViewportHeight() {
			if (frameId !== void 0) window.cancelAnimationFrame(frameId);
			frameId = window.requestAnimationFrame(() => {
				frameId = void 0;
				setViewportHeight(getViewportHeight());
				setIsMobileFooterVisible(getIsMobileFooterVisible());
			});
		}
		updateViewportHeight();
		window.addEventListener("resize", updateViewportHeight);
		window.addEventListener("orientationchange", updateViewportHeight);
		(_window$visualViewpor2 = window.visualViewport) === null || _window$visualViewpor2 === void 0 || _window$visualViewpor2.addEventListener("resize", updateViewportHeight);
		(_window$visualViewpor3 = window.visualViewport) === null || _window$visualViewpor3 === void 0 || _window$visualViewpor3.addEventListener("scroll", updateViewportHeight);
		return () => {
			var _window$visualViewpor4, _window$visualViewpor5;
			if (frameId !== void 0) window.cancelAnimationFrame(frameId);
			window.removeEventListener("resize", updateViewportHeight);
			window.removeEventListener("orientationchange", updateViewportHeight);
			(_window$visualViewpor4 = window.visualViewport) === null || _window$visualViewpor4 === void 0 || _window$visualViewpor4.removeEventListener("resize", updateViewportHeight);
			(_window$visualViewpor5 = window.visualViewport) === null || _window$visualViewpor5 === void 0 || _window$visualViewpor5.removeEventListener("scroll", updateViewportHeight);
		};
	}, []);
	return /* @__PURE__ */ react.default.createElement("div", {
		className: `venue-booking-scope ${isMobileFooterVisible ? "fixed" : ""} overflow-x-hidden overscroll-none bg-[#f5f5f3] text-zinc-900`,
		style: getViewportStyle(viewportHeight)
	}, /* @__PURE__ */ react.default.createElement(require_context.VenueBookingProvider, { entryContext }, /* @__PURE__ */ react.default.createElement(require_index.default, null)));
}
//#endregion
exports.default = VenueBooking;
