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

import Loadable from 'react-loadable';
import Loading from '../../Loading';
//业务组件
import CoursesBanner from "./coursesDetail/CoursesBanner";
import Coursesleftnav from "./coursesDetail/CoursesLeftNav";

//普通作业
const CommonWork = Loadable({
  loader: () => import('./busyWork/commonWork'),
  loading: Loading,
})
// 讨论
const Boards = Loadable({
  loader: () => import('./boards'),
  loading: Loading,
})
//教师列表
const TeacherList = Loadable({
  loader: () => import('./members/teacherList'),
  loading: Loading,
})
//主签到目录
const Signinmain = Loadable({
  loader: () => import('./signin/mymain/Signinmain'),
  loading: Loading,
});
//学生列表
const StudentsList = Loadable({
  loader: () => import('./members/studentsList'),
  loading: Loading,
});
//分班列表
const CourseGroupList = Loadable({
  loader: () => import('./members/CourseGroupList'),
  loading: Loading,
});

const Eduinforms = Loadable({
  loader: () => import('./gradinforms/Eduinforms'),
  loading: Loading,
});

//2019.10.29 统计
const Statistics = Loadable({
  loader: () => import('./statistics/Statistics'),
  loading: Loading,
});

const Elearning = Loadable({
  loader: () => import('./elearning/Elearning'),
  loading: Loading,
});
//
const Exercise = Loadable({
  loader: () => import('./exercise/Exercise'),
  loading: Loading,
})
//
const Poll = Loadable({
  loader: () => import('./poll/Poll'),
  loading: Loading,
})

// 资源
const Resourcelist = Loadable({
  loader: () => import('./Resource/index'),
  loading: Loading,
})

// 视频
const CourseVideo = Loadable({
  loader: () => import('./Video/VideoIndex'),
  loading: Loading,
})

//实训作业
const ShixunHomework = Loadable({
  loader: () => import('./shixunHomework/shixunHomework'),
  loading: Loading,
})

const GraduationTopics = Loadable({
  loader: () => import('./graduation/topics'),
  loading: Loading,
})
const GraduationTasks = Loadable({
  loader: () => import('./graduation/tasks'),
  loading: Loading,
})
class ListPageIndex extends Component {
  constructor(props) {
    super(props);
    this.state = {
      yslGuideone: undefined,
      yslElearning: false,
      isexcellent: false,
      homedirectory: false,
    }
  }
  comyslElearning(bool) {
    if (bool === true) {
      this.setState({
        yslElearning: true,
      })
    } else {
      this.setState({
        yslElearning: false,
      })
    }

  }
  componentDidMount() {
    var yslGuideone = window.localStorage.getItem('yslGuideone');
    try {
      if (yslGuideone === "true") {
        this.setState({
          yslGuideone: true,
        })
      } else {
        this.setState({
          yslGuideone: false,
        });
      }
    } catch (e) {
      console.log(e);
      this.setState({
        yslGuideone: false,
      });
    }


  }
  setwindowlocal = (bool) => {
    window.localStorage.setItem('yslGuideone', bool);
    try {
      if (bool === "true") {

        this.setState({
          yslGuideone: true,
        })
      } else {
        this.setState({
          yslGuideone: false,
        });

      }
    } catch (e) {
      this.setState({
        yslGuideone: false,
      });
    }
  }
  ispostexcellenttype = (excellent) => {
    this.setState({
      isexcellent: excellent
    })
  }
  updatabanners = () => {
    this.refs.CoursesBanner.updatabanner()
  }

  //是否点击了目录
  Callhomedirectoryornot = (bool) => {
    this.setState({
      homedirectory: bool
    })
    if (bool === true) {
      setTimeout(() => {
        this.setState({
          homedirectory: false,
        })
      }, 1000);
    }

  }
  render() {
    let { yslGuideone } = this.state;
    return (
      <div>
        <div className="newMain clearfix">
          <CoursesBanner ref={"CoursesBanner"} {...this.props} ispostexcellenttype={(excellent) => this.ispostexcellenttype(excellent)}></CoursesBanner>
          <div className="educontent clearfix" style={{ flex: "1 0 auto" }}>

            <div className="stud-class-set">
              <div className="news">
                <div className="edu-class-inner container clearfix">
                  <div className="member for-content-0 for-content">
                    <div className="people clearfix mb60">

                      {/*left_nav*/}
                      <div className={"with22 fl setleft"} style={{ width: '264px', minHeight: '500px' }}>
                        <Coursesleftnav {...this.props} {...this.state} comyslElearning={(i) => this.comyslElearning(i)} myinex={true} Callhomedirectoryornot={(b) => this.Callhomedirectoryornot(b)} />
                      </div>

                      {/*right_concent*/}
                      <div className="with78 fl">
                        <div className={"ml20 clearfix"}>
                          <Switch {...this.props}>
                            {/* 作业设置 */}
                            {/* http://localhost:3007/classrooms/1309/homework/9300/setting */}
                            {/* 普通作业 */}
                            <Route path="/classrooms/:coursesId/common_homeworks/:category_id"
                              render={
                                (props) => (<CommonWork {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/* 普通作业 */}
                            <Route path="/classrooms/:coursesId/common_homework/:category_id"
                              render={
                                (props) => (<CommonWork {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            {/* 作品列表 */}
                            <Route path="/classrooms/:coursesId/group_homeworks/:category_id"
                              render={
                                (props) => (<CommonWork {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/* 作品列表 */}
                            <Route path="/classrooms/:coursesId/group_homework/:category_id"
                              render={
                                (props) => (<CommonWork {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            <Route exact path="/classrooms/:coursesId/boards/:boardId"
                              render={
                                (props) => (<Boards {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/*视频列表*/}
                            <Route path="/classrooms/:coursesId/course_video/:videoId"
                              render={
                                (props) => (<CourseVideo {...this.props} {...props} {...this.state} homedirectory={this.state.homedirectory} />)
                              }
                            ></Route>
                            <Route path="/classrooms/:coursesId/course_videos"
                              render={
                                (props) => (<CourseVideo {...this.props} {...props} {...this.state} homedirectory={this.state.homedirectory} />)
                              }
                            ></Route>
                            {/* 教师列表*/}
                            <Route path="/classrooms/:coursesId/teachers"
                              render={
                                (props) => (<TeacherList updatabanners={() => this.updatabanners()} {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/* 学生列表*/}
                            <Route path="/classrooms/:coursesId/students"
                              render={
                                (props) => (<StudentsList {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/* 主签到 */}
                            <Route path="/classrooms/:coursesId/attendances"
                              render={
                                (props) => (<Signinmain {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            <Route path="/classrooms/:coursesId/course_groups/:course_group_id"
                              render={
                                (props) => (<StudentsList {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            <Route path="/classrooms/:coursesId/course_groups"
                              render={
                                (props) => (<CourseGroupList {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            <Route path="/classrooms/:coursesId/exercises/:Id"
                              render={
                                (props) => (<Exercise {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            <Route path="/classrooms/:coursesId/polls/:Id"
                              render={
                                (props) => (<Poll {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/* 实训作业子页面*/}
                            <Route path="/classrooms/:coursesId/shixun_homework/:category_id"
                              render={
                                (props) => (<ShixunHomework {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            {/*课堂统计列表2019.10.29 */}

                            <Route path="/classrooms/:coursesId/statistics"
                              render={
                                (props) => (<Statistics {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>


                            {/*公告栏列表*/}

                            <Route path="/classrooms/:coursesId/informs"
                              render={
                                (props) => (<Eduinforms {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/*在线学习*/}
                            <Route
                              path="/classrooms/:coursesId/online_learning"
                              render={
                                (props) => (<Elearning {...this.props} {...props} {...this.state} comyslElearning={(i) => this.comyslElearning(i)} />)
                              }
                            >
                            </Route>
                            {/* 实训作业页面*/}
                            <Route path="/classrooms/:coursesId/shixun_homeworks/:main_id"
                              render={
                                (props) => (<ShixunHomework {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>


                            <Route path="/classrooms/:coursesId/files/:main_id"
                              render={
                                (props) => (<Resourcelist {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            <Route path="/classrooms/:coursesId/file/:Id"
                              render={
                                (props) => (<Resourcelist {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                            <Route path="/classrooms/:coursesId/graduation_topics/:Id"
                              render={
                                (props) => (<GraduationTopics {...this.props} {...props} {...this.state} />)
                              }></Route>
                            <Route path="/classrooms/:coursesId/graduation_tasks/:Id"
                              render={
                                (props) => (<GraduationTasks {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>
                            {/* 默认 */}
                            <Route path="/classrooms/:coursesId"
                              render={
                                (props) => (<StudentsList {...this.props} {...props} {...this.state} />)
                              }
                            ></Route>

                          </Switch>
                        </div>
                      </div>

                    </div>
                  </div>
                </div>
              </div>
            </div>

          </div>
        </div>
      </div>
    )
  }
}
export default ListPageIndex;
