import { Navigate, Outlet } from 'react-router-dom';
import { useAuth } from '../../contexts/AuthContext'; // Adjust path if necessary

const AuthRoute = () => { // Renamed component from ProtectedRoute to AuthRoute
  const { user, isInitialized } = useAuth();

  // Wait for auth state to be initialized
  if (!isInitialized) {
    // You might want a loading spinner here
    return (
      <div className="min-h-screen flex items-center justify-center bg-campfire-dark">
         <div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-campfire-amber"></div>
      </div>
    );
  }

  // If user is not authenticated, redirect to login page
  if (!user) {
    return <Navigate to="/auth" replace />;
  }

  // If user is authenticated, render the child routes
  return <Outlet />;
};

export default AuthRoute; // Exporting AuthRoute
