import { useConvexAuth } from "convex/react";
import { Navigate, Outlet } from "react-router";

export default function AuthLayout() {
  const { isAuthenticated, isLoading } = useConvexAuth();

  if (isLoading) {
    return (
      <div className="grid min-h-svh place-items-center text-sm text-muted-foreground">
        Loading…
      </div>
    );
  }

  if (isAuthenticated) {
    return <Navigate replace to="/" />;
  }

  return (
    <main className="grid min-h-svh place-items-center bg-muted/30 p-6 md:p-10">
      <div className="w-full max-w-sm">
        <Outlet />
      </div>
    </main>
  );
}
