import React from "react";
import { ThemeProvider } from "./context/ThemeContext.jsx";
import { AuthProvider, useAuth } from "./context/AuthContext.jsx";
import AdminApp from "./pages/admin/AdminApp.jsx";
import UserApp from "./pages/user/UserApp.jsx";

function AppRoutes() {
  const { isAuthenticated, isAdmin, booting } = useAuth();

  if (booting || !isAuthenticated) {
    return (
      <div className="swi-login-page">
        <p className="swi-muted">Redirecting to HSE sign-in…</p>
      </div>
    );
  }

  if (isAdmin) {
    return <AdminApp />;
  }

  return <UserApp />;
}

export default function App() {
  return (
    <ThemeProvider>
      <AuthProvider>
        <AppRoutes />
      </AuthProvider>
    </ThemeProvider>
  );
}
