import { BrowserRouter as Router, Navigate, Route, Routes } from 'react-router-dom'
import { memo } from 'react'
import { ConfigProvider } from 'antd'
import locale from 'antd/lib/locale/ru_RU'

import { RootPathContext } from '@asb/context'
import { getUserToken, NoAccessComponent } from '@utils'
import { OpenAPI } from '@api'

import AdminPanel from '@pages/AdminPanel'
import Well from '@pages/Well'
import Login from '@pages/Login'
import Cluster from '@pages/Cluster'
import Deposit from '@pages/Deposit'
import Register from '@pages/Register'
import FileDownload from '@pages/FileDownload'

import '@styles/App.less'

//OpenAPI.BASE = 'http://localhost:3000'
OpenAPI.TOKEN = async () => getUserToken() ?? ''
OpenAPI.HEADERS = {'Content-Type': 'application/json'}

export const App = memo(() => (
    <ConfigProvider locale={locale}>
        <RootPathContext.Provider value={''}>
            <Router>
                <Routes>
                    <Route index element={<Navigate to={Deposit.getKey()} replace />} />
                    <Route path={'*'} element={<NoAccessComponent />} />

                    {/* Public pages */}
                    <Route path={Login.route} element={<Login />} />
                    <Route path={Register.route} element={<Register />} />

                    {/* Admin pages */}
                    <Route path={AdminPanel.route} element={<AdminPanel />} />

                    {/* User pages */}
                    <Route path={Deposit.route} element={<Deposit />} />
                    <Route path={Cluster.route} element={<Cluster />} /> 
                    <Route path={Well.route} element={<Well />} />
                    <Route path={FileDownload.route} element={<FileDownload />} />
                </Routes>
            </Router>
        </RootPathContext.Provider>
    </ConfigProvider>
))

export default App
