import { Redirect } from "expo-router";
import { ActivityIndicator, Text, View } from "react-native";
import { useAppStartup } from "../hooks/useAppStartup";

const startupMessages = {
	loading: "Loading app...",
	validating: "Validating data...",
	scannerMode: "Checking scanner mode...",
	normalScanner: "Starting normal ALPLAprod scanner that has no LST rules",
	checkingUpdates: "Checking for updates...",
	opening: "Opening LST scan app...",
	error: "Something went wrong during startup.",
};

export default function Index() {
	const { ready, startupRoute, status } = useAppStartup();

	if (ready && startupRoute) {
		return <Redirect href={startupRoute as any} />;
	}

	if (ready) {
		return <Redirect href="/login" />;
	}

	return (
		<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
			<Text>{startupMessages[status]}</Text>
			<ActivityIndicator size="large" />
		</View>
	);
}
