import Navbar from '@/components/common/navbar/Navbar';
import LoginPage from "@/components/pages/auth/Login";
import LLMConfigList from "@/components/pages/llmConfigs/LlmConfigList";
import LlmPromptList from "@/components/pages/llmPrompts/LlmPromptList";
import Logs from "@/components/pages/logs/Logs";
import Vectorization from "@/components/pages/vectorizationPage/Vectorization";
import { AuthProvider, useAuth } from "@/context/AuthContext";
import { pdfjs } from "react-pdf";
import { Navigate, Route, BrowserRouter as Router, Routes } from "react-router-dom";
import "./App.css";
import QePromptList from "./components/pages/qePrompts/QePromptList";


pdfjs.GlobalWorkerOptions.workerSrc = new URL(
  "pdfjs-dist/build/pdf.worker.min.mjs",
  import.meta.url
).toString();

const App: React.FC = () => {
  const { isAuthenticated } = useAuth();

  const PrivateRoute: React.FC<{ children: React.ReactNode }> = ({ children }) => {
    return isAuthenticated ? <>{children}</> : <Navigate to="/login" />;
  };

  return (
    <Router>
      <Navbar/>
      <div className="app-content">
        <Routes>
          <Route path="/login" element={<LoginPage />} />
          <Route path="/logs" element={
            <PrivateRoute>
              <Logs />
            </PrivateRoute>} />
          <Route path="/docs" element={
            <PrivateRoute>
              <Vectorization />
            </PrivateRoute>} />
          <Route path="/llmconfig" element={
            <PrivateRoute>
              <LLMConfigList />
            </PrivateRoute>
          } />
          <Route path="/llmprompt" element={
            <PrivateRoute>
              <LlmPromptList />
            </PrivateRoute>} />
          <Route path="/qeprompt" element={
            <PrivateRoute>
              <QePromptList />
            </PrivateRoute>} />            
        </Routes>
      </div>
    </Router>
  );
}

const RootApp: React.FC = () => (
  <AuthProvider>
    <App />
  </AuthProvider>
);

export default RootApp;
