/**
 * Main Application Component with Routing and Authentication
 * 
 * © 2025 Netwerk Digitaal Erfgoed & TextPast. All rights reserved.
 */

import {
  createBrowserRouter,
  RouterProvider,
  Navigate,
} from 'react-router-dom';
import { AuthProvider } from './contexts/AuthContext';
import { LanguageProvider } from './contexts/LanguageContext';
import { ProtectedRoute } from './components/ProtectedRoute';
import { Layout } from './components/layout/Layout';
import { Visualize } from './pages/Visualize';
import { Database } from './pages/Database';
import { Settings } from './pages/Settings';
import { LoginPage } from './pages/LoginPage';
import QueryBuilderPage from './pages/QueryBuilderPage';
import LinkMLViewerPage from './pages/LinkMLViewerPage';
import OntologyViewerPage from './pages/OntologyViewerPage';
import NDEMapPage from './pages/NDEMapPage';
import NDEStatsPage from './pages/NDEStatsPage';
import ProjectPlanPage from './pages/ProjectPlanPage';
import './App.css';

// Create router configuration with protected routes
// All pages use the standard Layout with navigation at the top
const router = createBrowserRouter([
  {
    path: '/login',
    element: <LoginPage />,
  },
  {
    path: '/',
    element: (
      <ProtectedRoute>
        <Layout />
      </ProtectedRoute>
    ),
    children: [
      {
        // Home page shows the Project Plan
        index: true,
        element: <ProjectPlanPage />,
      },
      {
        path: 'visualize',
        element: <Visualize />,
      },
      {
        path: 'database',
        element: <Database />,
      },
      {
        path: 'settings',
        element: <Settings />,
      },
      {
        path: 'query-builder',
        element: <QueryBuilderPage />,
      },
      {
        // Redirect old UML viewer route to unified visualize page
        path: 'uml-viewer',
        element: <Navigate to="/visualize" replace />,
      },
      {
        path: 'linkml',
        element: <LinkMLViewerPage />,
      },
      {
        path: 'ontology',
        element: <OntologyViewerPage />,
      },
      {
        path: 'map',
        element: <NDEMapPage />,
      },
      {
        path: 'stats',
        element: <NDEStatsPage />,
      },
    ],
  },
]);

function App() {
  return (
    <LanguageProvider>
      <AuthProvider>
        <RouterProvider router={router} />
      </AuthProvider>
    </LanguageProvider>
  );
}

export default App;
