function isAgentMobile() {
	const regex =
		/Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
	return regex.test(navigator.userAgent);
}

function hasTouchSupport() {
	return "ontouchstart" in window || navigator.maxTouchPoints > 0;
}

function isMobileScreen() {
	const minWidth = 768; // Minimum width for desktop devices
	return window.innerWidth < minWidth || screen.width < minWidth;
}

function isMobile() {
	// Check if at least 2 of the 3 conditions are true

	const isMobileAgent = isAgentMobile(); // Renamed variable to avoid conflict
	const touchSupport = hasTouchSupport(); // Renamed variable to avoid conflict
	const mobileScreen = isMobileScreen(); // Renamed variable to avoid conflict

	const conditions = [isMobileAgent, touchSupport, mobileScreen];
	const trueConditions = conditions.filter((condition) => condition);

	return trueConditions.length >= 2; // Return true if at least 2 conditions are true
}

const user = isMobile();

// Check if the user is on a mobile device
if (user) {
	if (DEBUG) console.log("User is on a mobile device, changing userAgent.");
	browser.storage.sync.set({ isMobile: user });
}
