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 Signinmain = Loadable({
  loader: () => import('./signin/mymain/Signinmain'),
  loading: Loading,
});
const Elearning = Loadable({
  loader: () => import('./elearning/Elearning'),
  loading: Loading,
});
//
const Exercise = Loadable({
  loader: () => import('./exercise/Exercise'),
  loading: Loading,
})


//实训作业
const ShixunHomework = Loadable({
  loader: () => import('./shixunHomework/shixunHomework'),
  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 path="/classrooms/:coursesId/attendances"
                              render={
                                (props) => (<Signinmain {...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/shixun_homework/:category_id"
                              render={
                                (props) => (<ShixunHomework {...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>
                          </Switch>
                        </div>
                      </div>

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

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