import React from 'react';
import { useRouter } from 'next/navigation';
import { useAuth } from '../context/AuthContext';

const ProtectedRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
  const { user } = useAuth();
  const router = useRouter();

  React.useEffect(() => {
    if (!user) {
      router.push('/'); // Redirect to login page if not authenticated
    }
  }, [user, router]);

  if (!user) {
    return null; // Optionally, you can return a loading spinner here
  }

  return <>{children}</>;
};

export default ProtectedRoute;