import { Navigate } from "react-router-dom";
import { useAuth } from "@/contexts/AuthContext";

/** Public-only route (e.g. sign-in). Authenticated users are sent to the app root. */
export function GuestRoute({ children }: { children: React.ReactNode }) {
  const { isAuthenticated, loading } = useAuth();

  if (loading) {
    return (
      <div className="min-h-screen flex items-center justify-center bg-background">
        <p className="text-muted-foreground font-display">Loading…</p>
      </div>
    );
  }

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

  return <>{children}</>;
}
