import { Redirect, Stack } from "expo-router";
import { View } from "react-native";

import { useAuthContext } from "@/auth/AuthContext";
import { LoadingSpinner } from "@/components/ui/LoadingSpinner";

const AuthRoutesLayout = () => {
  const { isAuthenticated, bootstrapping } = useAuthContext();

  if (bootstrapping) {
    return (
      <View className="flex-1 p-5 bg-primaryPurpleLight">
        <View
          style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
        >
          <LoadingSpinner />
        </View>
      </View>
    );
  }

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

  return <Stack screenOptions={{ headerShown: false }} />;
};

export default AuthRoutesLayout;
