require("../_virtual/_rolldown/runtime.js");
const require_index = require("../utils/index.js");
let react = require("react");
//#region src/hooks/useResponsive.ts
const subscribers = /* @__PURE__ */ new Set();
let info;
let responsiveConfig = {
	phone: 0,
	ipad: 800,
	pc: 1080
};
function handleResize() {
	const oldInfo = info;
	calculate();
	if (oldInfo === info) return;
	for (const subscriber of subscribers) subscriber();
}
let listening = false;
function calculate() {
	const width = window.innerWidth;
	const newInfo = {};
	let shouldUpdate = false;
	for (const key of Object.keys(responsiveConfig)) {
		newInfo[key] = width >= responsiveConfig[key];
		if (newInfo[key] !== info[key]) shouldUpdate = true;
	}
	if (shouldUpdate) info = newInfo;
}
function configResponsive(config) {
	responsiveConfig = config;
	if (info) calculate();
}
function useResponsive() {
	if (require_index.isBrowser && !listening) {
		info = {};
		calculate();
		window.addEventListener("resize", handleResize);
		listening = true;
	}
	const [state, setState] = (0, react.useState)(info);
	(0, react.useEffect)(() => {
		if (!require_index.isBrowser) return;
		if (!listening) window.addEventListener("resize", handleResize);
		const subscriber = () => {
			setState(info);
		};
		subscribers.add(subscriber);
		return () => {
			subscribers.delete(subscriber);
			if (subscribers.size === 0) {
				window.removeEventListener("resize", handleResize);
				listening = false;
			}
		};
	}, []);
	return (0, react.useMemo)(() => {
		if (state === null || state === void 0 ? void 0 : state.pc) return "pc";
		if (state === null || state === void 0 ? void 0 : state.ipad) return "ipad";
		return "phone";
	}, [state]);
}
//#endregion
exports.configResponsive = configResponsive;
exports.default = useResponsive;
