"use client";

import { SignIn } from "@/components/auth/SignIn";
import { Authenticated, Unauthenticated, useQuery } from "convex/react";
import { api } from "@/convex/_generated/api";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

export default function AuthPage() {
    const router = useRouter();

    return (
        <div className="min-h-screen flex items-center justify-center bg-background">
            <Unauthenticated>
                <SignIn />
            </Unauthenticated>
            <Authenticated>
                <RedirectToDashboard />
            </Authenticated>
        </div>
    );
}

function RedirectToDashboard() {
    const router = useRouter();
    useEffect(() => {
        router.push("/dashboard");
    }, [router]);

    return (
        <div className="text-center">
            <h1 className="text-2xl font-bold mb-4">You are logged in!</h1>
            <p>Redirecting to dashboard...</p>
        </div>
    );
}
