import { Layout, Menu } from 'antd'
import { Switch, Link, useParams, Redirect, Route } from 'react-router-dom'
import { PrivateMenuItem, PrivateRoute } from '../../components/Private'
import { ClusterController } from './ClusterController'
import { CompanyController } from './CompanyController'
import { DepositController } from './DepositController'
import { UserController } from './UserController'
import { WellController } from './WellController'

export const AdminPanel = () => {
    const { tab } = useParams()
    const rootPath = '/admin'

    return (
        <Layout>
            <Menu
                mode={'horizontal'}
                selectable={true}
                selectedKeys={[tab]}
            >
                <PrivateMenuItem roles={['deposit_admin']} key={'deposit'}>
                    <Link to={`${rootPath}/deposit`}>Управление месторождениями</Link>
                </PrivateMenuItem>
                <PrivateMenuItem roles={['cluster_admin']} key={'cluster'}>
                    <Link to={`${rootPath}/cluster`}>Управление кустами</Link>
                </PrivateMenuItem>
                <PrivateMenuItem roles={['well_admin']} key={'well'}>
                    <Link to={`${rootPath}/well`}>Управление скважинами</Link>
                </PrivateMenuItem>
                <PrivateMenuItem roles={['user_admin']} key={'user'}>
                    <Link to={`${rootPath}/user`}>Управление пользователями</Link>
                </PrivateMenuItem>
                <PrivateMenuItem roles={['company_admin']} key={'company'}>
                    <Link to={`${rootPath}/company`}>Управление компаниями</Link>
                </PrivateMenuItem>
            </Menu>

            <Layout>
                <Layout.Content className={'site-layout-background'}>
                    <Switch>
                        <PrivateRoute roles={['deposit_admin']} path={`${rootPath}/deposit/:page?`}>
                            <DepositController />
                        </PrivateRoute>
                        <PrivateRoute roles={['cluster_admin']} path={`${rootPath}/cluster/:page?`}>
                            <ClusterController />
                        </PrivateRoute>
                        <PrivateRoute roles={['well_admin']} path={`${rootPath}/well/:page?`}>
                            <WellController />
                        </PrivateRoute>
                        <PrivateRoute roles={['user_admin']} path={`${rootPath}/user/:page?`}>
                            <UserController />
                        </PrivateRoute>
                        <PrivateRoute roles={['company_admin']} path={`${rootPath}/company/:page?`}>
                            <CompanyController />
                        </PrivateRoute>
                        <Route path={'/'}>
                            <Redirect to={`${rootPath}/deposit`}/>
                        </Route>
                    </Switch>
                </Layout.Content>
            </Layout>
        </Layout>
    )
}

export default AdminPanel
