import { createBrowserRouter, Navigate } from 'react-router';
import { ProtectedRoute } from './components/ProtectedRoute';
import { MainLayout } from './layouts/MainLayout';
import { ErrorPage } from './components/ErrorPage';
import { NotFoundPage } from './components/NotFoundPage';
import { DashboardPage } from './pages/Dashboard';
import { UsersPage } from './pages/Users';
import { LoginPage } from './pages/Login';
import { FilesPage } from './pages/Files';
import { ActivitiesPage } from './pages/Activities';
import { RoutesPage } from './pages/Routes';
import { AreasPage } from './pages/Areas';
import { LocationsPage } from './pages/Locations';
import { PassengersPage } from './pages/Passengers';
import { OrdersPage } from './pages/Orders';

export const router = createBrowserRouter([
  {
    path: '/',
    element: <Navigate to="/admin" replace />
  },
  {
    path: '/admin/login',
    element: <LoginPage />
  },
  {
    path: '/admin',
    element: (
      <ProtectedRoute>
        <MainLayout />
      </ProtectedRoute>
    ),
    children: [
      {
        index: true,
        element: <Navigate to="/admin/dashboard" />
      },
      {
        path: 'dashboard',
        element: <DashboardPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'users',
        element: <UsersPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'files',
        element: <FilesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'activities',
        element: <ActivitiesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'routes',
        element: <RoutesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'areas',
        element: <AreasPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'locations',
        element: <LocationsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'passengers',
        element: <PassengersPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'orders',
        element: <OrdersPage />,
        errorElement: <ErrorPage />
      },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
  {
    path: '*',
    element: <NotFoundPage />,
    errorElement: <ErrorPage />
  },
]);