import { PortalHost } from "@rn-primitives/portal";
import { Stack } from "expo-router";
import { StatusBar } from "expo-status-bar";
import "../../global.css";
import { QueryClientProvider } from "@tanstack/react-query";
import { useEffect } from "react";
import Toast from "react-native-toast-message";
import useDeviceLock from "../hooks/useDeviceCheck";
import { useDeviceOrientationLock } from "../hooks/useDeviceOrientationLock";
import { queryClient } from "../lib/queryStuff/queryClient";
import { connectSocket } from "../lib/socket.io";
import { zebraScanner } from "../lib/ZebraScanner";

export default function RootLayout() {
	useDeviceLock();
	useDeviceOrientationLock();

	useEffect(() => {
		zebraScanner.ensureProfile();
		connectSocket();
	}, []);

	return (
		<>
			<QueryClientProvider client={queryClient}>
				<StatusBar style="dark" />
				<Stack screenOptions={{ headerShown: false }}>
					<Stack.Screen name="index" />
					<Stack.Screen name="login" />
					<Stack.Screen name="setup" />
					<Stack.Screen name="updateScreen" />
					<Stack.Screen name="(tabs)" />
				</Stack>
				<PortalHost />
			</QueryClientProvider>

			<Toast />
		</>
	);
}
