import { useEffect, useState } from "react";
function readPhoneByWidth() {
	if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
	return window.matchMedia(`(max-width: 768px)`).matches;
}
/**
* 监听视口宽度，得到预约页应使用的 `variant`。
*
* - 调用方显式传入 `forced` 时，优先使用之，避免覆盖业务/低代码意图（见 responsive 规则中 props 优先级）；
* - 否则按断点动态返回 `'phone'` / `'desktop'`，并在 resize / orientation 变化时同步更新。
*
* @param forced 调用方显式指定的 variant；不传则按断点判定
*/
function useReservationResponsiveVariant(forced) {
	const [isPhone, setIsPhone] = useState(() => readPhoneByWidth());
	useEffect(() => {
		var _legacy$addListener;
		if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
		const mql = window.matchMedia(`(max-width: 768px)`);
		const handle = (event) => {
			setIsPhone(Boolean(event.matches));
		};
		handle(mql);
		if (typeof mql.addEventListener === "function") {
			mql.addEventListener("change", handle);
			return () => {
				mql.removeEventListener("change", handle);
			};
		}
		/** Safari < 14 兼容：addListener / removeListener */
		const legacy = mql;
		(_legacy$addListener = legacy.addListener) === null || _legacy$addListener === void 0 || _legacy$addListener.call(legacy, handle);
		return () => {
			var _legacy$removeListene;
			(_legacy$removeListene = legacy.removeListener) === null || _legacy$removeListene === void 0 || _legacy$removeListene.call(legacy, handle);
		};
	}, []);
	if (typeof forced === "string" && forced.length > 0) return forced;
	return isPhone ? "phone" : "desktop";
}
//#endregion
export { useReservationResponsiveVariant as default };
