import React from 'react'
import { Layout } from 'antd'
import { Route, Switch } from 'dva/router'
import { Redirect } from 'dva/router'
import Navigator from '../components/common/navigator'
import HomePage from '../components/homePage/homePage'
import Loading from '../components/common/loading/loading'
import DataSourceDetail from '../components/datasource/dataSourceDetail'
import DataSource from '../components/datasource/dataSource'
import Dashboard from '../components/dashboard/list'
import Chart from '../components/chart/list'
import './mainLayout.less';
import Demo from '../demo';
import Admin from '../components/admin/admin';
const { Header, Content } = Layout

const MainLayout = ({ isAuthenticated }) => {
    return(
        <Layout className='main-layout'>
            <Loading />
            <Header className='main-header'>
                <Navigator />
            </Header>
            <Content className='main-content'>
                <Switch>
                    <Route sensitive path='/demo' component={Demo}/>
                    <Route sensitive path='/home' component={HomePage}/>
                    <Route sensitive path='/datasource/:type/:code/:tab' component={DataSourceDetail}/>
                    <Route sensitive path='/datasource' component={DataSource}/>
                    <Route sensitive path='/dashboard' component={Dashboard} />
                    <Route sensitive path='/chart' component={Chart} />
                    <Route sensitive path='/admin' component={Admin} />
                    <Route path='/' component={isAuthenticated ? HomePage : () => <Redirect
                        to={{
                            pathname: "/login",
                            state: { from: '/' }
                        }}
                    />}/>
                </Switch>
            </Content>
        </Layout>
    )
}
export default MainLayout;