import { Navigate, Outlet } from 'react-router-dom';
import { useContext } from 'react';
import { AuthContext } from './AuthProvider';
import LoadingScreen from '../components/LoadingScreen';

function ProtectedRoutes() {
  const { authorized } = useContext(AuthContext);

  if (authorized === null) {
    return <LoadingScreen />;
  }

  return authorized ? <Outlet /> : <Navigate to="/login" replace />;
}

export default ProtectedRoutes;
