import * as React from "react";
import { Routes, Route, Navigate, useNavigate } from "react-router-dom";
import HomePage from './screens/HomePage';
import PageOne from './screens/Page1';
import AuthorizeScreen from "./screens/Authorize";
import { useSession } from "./contexts/AuthContext";

const AppScreens: React.FC = () => {
  const navigate = useNavigate();
  const { status } = useSession();

  React.useEffect(() => {
    if (status === 'unauthenticated') {
      navigate('/authorize');
    }
  }, [status, navigate]);

  return (
    <Routes>
      <Route path="/" element={<HomePage />} />
      <Route path="/authorize" element={<AuthorizeScreen />} />
      <Route path="*" element={<Navigate to="/" />} />
    </Routes>
  );
};

export default AppScreens;
