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

function PublicRoute() {
  const { authorized, isLoading } = useContext(AuthContext);

  if (isLoading) {
    return <LoadingScreen />;
  }

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

export default PublicRoute;
