import React from 'react';
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 { AdvertisementsPage } from './pages/Advertisements';
import { AdvertisementTypesPage } from './pages/AdvertisementTypes';
import { GoodsCategories } from './pages/GoodsCategories';
import { GoodsPage } from './pages/Goods';
import { ExpressCompaniesPage } from './pages/ExpressCompanies';
import { SuppliersPage } from './pages/Suppliers';
import { MerchantsPage } from './pages/Merchants'
import { AgentsPage } from './pages/Agents';

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: 'advertisements',
        element: <AdvertisementsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'advertisement-types',
        element: <AdvertisementTypesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'goods-categories',
        element: <GoodsCategories />,
        errorElement: <ErrorPage />
      },
      {
        path: 'goods',
        element: <GoodsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'express-companies',
        element: <ExpressCompaniesPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'suppliers',
        element: <SuppliersPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'merchants',
        element: <MerchantsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: 'agents',
        element: <AgentsPage />,
        errorElement: <ErrorPage />
      },
      {
        path: '*',
        element: <NotFoundPage />,
        errorElement: <ErrorPage />
      },
    ],
  },
  {
    path: '*',
    element: <NotFoundPage />,
    errorElement: <ErrorPage />
  },
]);