'use client';


import { useEffect, useState } from "react";

//#region src/hooks/useDevice.ts
const getBreakpointFromSize = (breakpoint) => {
	switch (breakpoint) {
		case "xs": return 480;
		case "sm": return 640;
		case "md": return 768;
		case "lg": return 1024;
		case "xl": return 1280;
		case "2xl": return 1536;
		default: return breakpoint;
	}
};
const checkIsMobileUserAgent = () => {
	if (typeof window === "undefined") return;
	const userAgent = window.navigator?.userAgent;
	if (typeof userAgent === "undefined") return;
	return /android|bb\d+|meego|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(?:hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(?:ob|in)i|palm(?: os)?|phone|p(?:ixi|re)\/|plucker|pocket|psp|series(?:4|6)0|symbian|treo|up\.(?:browser|link)|vodafone|wap|windows ce|windows phone|xda|xiino|zte-/i.test(userAgent);
};
const checkIsIphoneOrSafariDevice = () => {
	if (typeof window === "undefined") return;
	const userAgent = window.navigator?.userAgent;
	const isSafari = /Safari\/\d/i.test(userAgent) && !/Chrome|CriOS|FxiOS|Edg|OPR/i.test(userAgent);
	const isAppleDevice = /Macintosh|iP(?:hone|ad|od)/.test(userAgent);
	return isSafari && isAppleDevice;
};
const checkIsMobileScreen = (breakpoint) => {
	if (typeof window === "undefined") return;
	return (window?.innerWidth ?? 0) <= breakpoint;
};
const calculateIsMobile = (breakpoint = "md") => {
	const breakpointValue = getBreakpointFromSize(breakpoint);
	const isMobileUserAgent = checkIsMobileUserAgent();
	const isMobileScreen = checkIsMobileScreen(breakpointValue);
	return {
		isMobileScreen,
		isMobileUserAgent,
		isMobile: isMobileScreen ?? isMobileUserAgent
	};
};
const useDevice = (breakpoint = "md") => {
	const [result, setResult] = useState(calculateIsMobile(breakpoint));
	useEffect(() => {
		const handleResize = () => {
			setResult(calculateIsMobile(breakpoint));
		};
		window.addEventListener("resize", handleResize, { passive: true });
		return () => window.removeEventListener("resize", handleResize);
	}, [breakpoint]);
	return result;
};

//#endregion
export { calculateIsMobile, checkIsIphoneOrSafariDevice, checkIsMobileScreen, checkIsMobileUserAgent, getBreakpointFromSize, useDevice };
//# sourceMappingURL=useDevice.mjs.map