import styles from "./LoginPage.module.css";
import LoginForm from "./components/loginform/loginForm.jsx";
import Background from "../../components/background/background.jsx";
import { useEffect, useContext } from "react";
import { AuthContext } from "../../contexts/auth/AuthContext.js";
import { useNavigate } from "react-router";

function LoginPage() {

    const { user, loading } = useContext(AuthContext)
    const navigate = useNavigate();



    useEffect(() => {
        console.log("loading" + loading);
        console.log("user" + user);

        if (!loading && user) {
            navigate("/");
        }
    }, [loading, navigate, user]);

    return (
        <Background>
            <div className={styles.container}>
                <h1 className={styles.title}>Connexion</h1>
                <LoginForm />
            </div>
        </Background>
    );
}

export default LoginPage;
