import React, { Component } from "react";
import { Route, Switch } from "react-router-dom";
import { connect } from 'react-redux';

import { GetSession } from "../../util";
import { ManageLayout } from "../../layout";

import DatasourceManage from './DatasourceManage';
import Model from './Model';
import ModelConfig from './ModelConfig';
import DataService from './Pdata';
import AssetDraft from './AssetDraft';
import AssetManage from './AssetManage';
import AssetBrowse from './AssetBrowse';
import AssetTask from './AssetTask';
import AssetEvaluate from "./AssetEvaluate";
import DataMasterDefine from "./DataMaster/Define";
import DataMasterManage from "./DataMaster/Manage";

class Manage extends Component {

  render() {
    const { match } = this.props
    const { session } = this.props;

    return (
      <React.Fragment>
        <ManageLayout
          {...this.props}
          content={
            session && session.userId ? (
              <Switch>
                <Route path={`${match.path}/datasource-manage`} component={DatasourceManage} />
                <Route path={`${match.path}/data-service`} component={DataService} />
                <Route path={`${match.path}/data-model`} component={Model} />
                <Route path={`${match.path}/model-config`} component={ModelConfig} />
                <Route path={`${match.path}/asset-draft`} component={AssetDraft} />
                <Route path={`${match.path}/asset-manage`} component={AssetManage} />
                <Route path={`${match.path}/asset-browse`} component={AssetBrowse} />
                <Route path={`${match.path}/asset-task`} component={AssetTask} />
                <Route path={`${match.path}/asset-evaluate`} component={AssetEvaluate} />
                <Route path={`${match.path}/msd-define`} component={DataMasterDefine} />
                <Route path={`${match.path}/msd-manage`} component={DataMasterManage} />
              </Switch>
            ) : (
              <GetSession {...this.props} />
            )
          }
        />
      </React.Fragment>
    )
  }
}

export default connect(
  state => {
    return {session: state.sessionState}
  }
)(Manage);