import React, { useEffect, useState } from "react";

import { Route, Switch } from "react-router-dom";
import { withRouter } from "react-router";
import { SnackbarHOC } from "educoder";
import { CNotificationHOC } from "../modules/courses/common/CNotificationHOC";
import { TPMIndexHOC } from "../modules/tpm/TPMIndexHOC";
import Loadable from "react-loadable";
import Loading from "../Loading";
import { getUserInfo } from './expert/api';
import { ImageLayerOfCommentHOC } from "../modules/page/layers/ImageLayerOfCommentHOC";
import './index.scss';

const Review = Loadable({
  loader: () => import("./expert/review/review"),
  loading: Loading,
});

const ExpertUser = Loadable({
  loader: () => import("./expert/expertUser"),
  loading: Loading,
})
const Expert = (propsTransmit) => {

  // 开发时，从代理的位置获取用户信息
  const [currentUser, setCurrentUser] = useState(propsTransmit.current_user);
  // const isDev = window.location.href.indexOf('3007') > -1 ? true : false;
  useEffect(() => {
    getUserInfo().then(res => {
      if (res && res.data) {
        setCurrentUser(res.data);
      }
    })
  }, []);
  let propsF = { ...propsTransmit };
  propsF.current_user = {...propsF.current_user,...currentUser};

  return (
    <div className="newMain clearfix">
      <Switch {...propsF}>
        {/* 专家注册、专家评审任务 */}
        <Route
          path="/expert/user/:functional"
          render={(props) => (
            <ExpertUser {...propsF} {...props} />
          )}
        ></Route>

        <Route
          path="/expert"
          render={(props) => (
            <Review {...propsF} {...props} />
          )}
        ></Route>

       
      </Switch>
    </div>
  );
}

export default withRouter(
  ImageLayerOfCommentHOC({
    imgSelector: ".imageLayerParent img, .imageLayerParent .imageTarget",
    parentSelector: ".newMain",
  })(CNotificationHOC()(SnackbarHOC()(TPMIndexHOC(Expert))))
);
