import { createContext, memo } from 'react'
import { Route, Switch } from 'react-router-dom'

import { AdminLayoutPortal, LayoutPortal } from '@components/Layout'
import { PrivateDefaultRoute, PrivateRoute } from '@components/Private'

import Well from './Well'
import Cluster from './Cluster'
import Deposit from './Deposit'
import AdminPanel from './AdminPanel'
import AccessDenied from './AccessDenied'

export const RootPathContext = createContext('')

export const Main = memo(() => (
    <RootPathContext.Provider value={''}>
        <Switch>
            <PrivateRoute path={'/admin/:tab?'}>
                <AdminLayoutPortal title={'Администраторская панель'}>
                    <AdminPanel />
                </AdminLayoutPortal>
            </PrivateRoute>
            <PrivateRoute path={'/deposit'}>
                <LayoutPortal noSheet title='Месторождение'>
                    <Deposit />
                </LayoutPortal>
            </PrivateRoute>
            <PrivateRoute path={'/cluster/:idCluster'}>
                <LayoutPortal title={'Анализ скважин куста'}>
                    <Cluster />
                </LayoutPortal>
            </PrivateRoute>
            <PrivateRoute path={'/well/:idWell/:tab?'}>
                <LayoutPortal>
                    <Well />
                </LayoutPortal>
            </PrivateRoute>
            <Route path={'/access_denied'}>
                <AccessDenied />
            </Route>
            <PrivateDefaultRoute urls={['/deposit']} />
        </Switch>
    </RootPathContext.Provider>
))

export default Main
