import { useEffect, useState } from "react";
//#region src/components/list/hooks/useDevice.ts
/**
* 设备检测Hook
* 根据屏幕宽度和用户代理判断当前设备类型
*/
const useDevice = () => {
	const [deviceInfo, setDeviceInfo] = useState(() => {
		const initialWidth = typeof window !== "undefined" ? window.innerWidth : 1920;
		const initialHeight = typeof window !== "undefined" ? window.innerHeight : 1080;
		const initialType = getDeviceType(initialWidth);
		return {
			type: initialType,
			isMobile: initialType === "mobile",
			isPad: initialType === "pad",
			isPc: initialType === "pc",
			width: initialWidth,
			height: initialHeight
		};
	});
	useEffect(() => {
		const handleResize = () => {
			const width = window.innerWidth;
			const height = window.innerHeight;
			const type = getDeviceType(width);
			setDeviceInfo({
				type,
				isMobile: type === "mobile",
				isPad: type === "pad",
				isPc: type === "pc",
				width,
				height
			});
		};
		handleResize();
		window.addEventListener("resize", handleResize);
		return () => {
			window.removeEventListener("resize", handleResize);
		};
	}, []);
	return deviceInfo;
};
/**
* 根据屏幕宽度判断设备类型
* @param width 屏幕宽度
* @returns 设备类型
*/
function getDeviceType(width) {
	if (width < 768) return "mobile";
	else if (width < 1200) return "pad";
	else return "pc";
}
//#endregion
export { useDevice };
