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

interface ProtectedRouteProps {
  children: React.ReactNode;
  fallback?: string;
}

/**
 * ProtectedRoute component.
 * Redirects to auth page if user is not signed in.
 */
export function ProtectedRoute({ children, fallback = ROUTES.AUTH }: ProtectedRouteProps) {
  const { currentUser, isInitialized, isLoading } = useAuth();
  
  if (isLoading || !isInitialized) {
      return null;
  }

  if (!currentUser) {
      return <Navigate to={fallback} replace />;
  }

  return <>{children}</>;
}
