import React from 'react';
import { Route, Switch } from "react-router-dom";
import Loadable from "react-loadable";
import Loading from "../../Loading";
import { withRouter } from "react-router";
import { SnackbarHOC } from "educoder";
import { CNotificationHOC } from "../../modules/courses/common/CNotificationHOC";
import { TPMIndexHOC } from "../../modules/tpm/TPMIndexHOC";
const Infos = Loadable({
  loader: () => import("./Infos"),
  loading: Loading,
});
// forge项目详情
const ProjectDetail = Loadable({
  loader: () => import("../Main/Detail"),
  loading: Loading,
});
export default withRouter(
  (CNotificationHOC()(SnackbarHOC()(TPMIndexHOC((props) => {

    // 个人中心新增的二级目录都需在此添加一次。将项目放组织和个人名下后，此处根据二级目录作判断，
    let secondRouter = '';
    if (props.location.pathname) {
      secondRouter = props.location.pathname.split('/')[2];
    }
    
    let userRouterArr = ['statistics', 'projects', 'notice', 'devops', 'organizes', 'info', 'following', 'followers', 'password'];
    return (
      <Switch>

        {secondRouter && (!userRouterArr.includes(secondRouter)) ? <Route
          path="/:owner/:projectsId"
          render={(p) => (
            <ProjectDetail  {...props} {...p} />
          )}
        ></Route> : <Route
          path="/:username"
          render={(p) => (
            <Infos {...props} {...p} />
          )}
        ></Route>}

      </Switch>
    )
  }))))
)