import React, {Component} from "react";
import {Link, NavLink} from 'react-router-dom';
import {WordsBtn, ActionBtn,SnackbarHOC,getImageUrl,queryString} from 'educoder';
import axios from 'axios';
import {
	notification,
	Spin,
	Table,
	Pagination,
	Tabs,
	Input,
	Popover
} from "antd";
import './../testioncss/testioncss.css';

import NoneDatas from '../component/NoneDatas';
import Contentquestionbank from "./Contentquestionbank";
import LoadingSpin from '../../../common/LoadingSpin';
import Listjihe from "./Listjihe";
import Certifiedprofessional from "../../modals/Certifiedprofessional";
import SendTopicsModel from "./SendTopicsModel";
const { TabPane } = Tabs;
const Search = Input.Search;
class Contentpart extends Component {
	constructor(props) {
		super(props);
		this.state = {
			page:1,
			defaultActiveKeyss:"0",
			mydisplay:false,
			occupation:2,
			isysladmins:false,
			SendTop:false,
			paramsid:null,
			mysauth_roles:false,
			myPeriofters:false,
		}
	}
	//初始化
	componentDidMount(){
		const query = this.props.location.search;
		const parsed = queryString.parse(query);
		console.log("Contentpart");
		console.log(parsed);
		if(JSON.stringify(parsed)==="{}"){
			this.setState({
				defaultActiveKeyss:"0",
			})
		}else {
			if(parsed.defaultActiveKey==="0"){
				this.setState({
					defaultActiveKeyss:"0",
				})
			}else{
				this.setState({
					defaultActiveKeyss:"1",
				})
			}

		}
		let isysladmins=false;
		if(this.props){
			if(this.props.current_user){
				if(this.props.current_user.admin){
					isysladmins=true;
				}
				else if(this.props.current_user.business){
					isysladmins=true;
				}
			}
		}



		let auth_roles =this.props.auth_role;
		let Periofters = false;
		if (this.props) {
			if (this.props.current_user) {
				if (this.props.current_user.admin) {
					Periofters = true;
				}
				else if (this.props.current_user.business) {
					Periofters = true;
				}
				else if (this.props.current_user.is_shixun_marker) {
					Periofters = true;
				}
				else if (this.props.current_user.is_teacher) {
					Periofters = true;
				} else if (this.props.current_user.user_identity !== "学生") {
					Periofters = true;
				}
			}
		}

		this.setState({
			mysauth_roles:auth_roles,
			myPeriofters:Periofters,
		})

	}
	//跳转人工组卷
	Mantegeneration=()=>{
		this.props.history.push('/problemset');
	}


	componentDidUpdate(prevProps) {
		if(prevProps.current_user !== this.props.current_user) {
			let isysladmins=false;
			let is_teacher=this.props&&this.props.current_user&&this.props.current_user.is_teacher?this.props.current_user.is_teacher:false;
			const professional_certification=this.props&&this.props.current_user&&this.props.current_user.professional_certification?this.props.current_user.professional_certification:false;
			let {defaultActiveKey} = this.props;
			let defaultActiveKeys=defaultActiveKey;
		try {
			if(this.props){
				if(this.props.current_user){
					if(this.props.current_user.admin){
						isysladmins=true;
					}
					else if(this.props.current_user.business){
						isysladmins=true;
					}
				}
			}

			if(is_teacher===false){
				if(this.props.current_user.user_identity !=="学生"){
					//专业人士
					is_teacher=true
				}
			}
		}catch (e) {

		}
			if(isysladmins===true||(is_teacher===true&&professional_certification===true)){
				defaultActiveKeys="0"
			}else{
				defaultActiveKeys="1"
			}
			try {
				if(this.props.defaultActiveKeybool===false){
					if (this.state.defaultActiveKeyss==="0"){
						defaultActiveKeys="0"
					} else {
						defaultActiveKeys="1"
					}
				}
			}catch (e) {

			}


			this.props.callback(defaultActiveKeys,false);
		}
	}
	HideAddcoursestypess=(i)=>{
	 try {
		 if(this.props.current_user.professional_certification===false&&this.state.isysladmins===false){
			 this.setState({
				 mydisplay:true,
				 occupation:i,
			 })
		 }
	 }catch (e) {

	 }

	}

	mydisplayHidedel=()=>{
		this.setState({
			mydisplay:false,
		})
	}
	xinzenw=(url,b)=>{
		if(b===false){
			//只限制了教师
				this.HideAddcoursestypess(2);
				return
		}


		this.props.history.push(url);

	}
	HideAddcoursestypess=(i)=>{
		console.log("调用了");
		this.setState({
			mydisplay:true,
			occupation:i,
		})
	}

	mydisplayHidedel=()=>{
		this.setState({
			mydisplay:false,
		})
	}

	Testpapereditor=(e)=>{


    	if(this.props.auth_role===false){
			this.HideAddcoursestypess(2);
			return
		}
		this.props.Testpapereditor(e)

	}

	showmodels=(e)=>{

		if(this.props.auth_role===false){
			this.HideAddcoursestypess(2);
			return
		}
		this.props.showmodels(e)

	}


	showmodelysl=(e)=>{

		if(this.props.auth_role===false){
			this.HideAddcoursestypess(2);
			return
		}
		this.props.showmodelysl(e)

	}


	showmodelsInaudit=(e)=>{

		if(this.props.auth_role===false){
			this.HideAddcoursestypess(2);
			return
		}
		this.props.showmodelsInaudit(e)

	}

	submitInfos=(bool,id)=>{
		this.setState({
			SendTop:bool,
			paramsid:id
		})
	}

	render() {
		let {page,defaultActiveKeyss,mydisplay,SendTop,paramsid}=this.state;
		let {defaultActiveKey,defaultActiveKeybool}=this.props;
    let defaultActiveKeys=defaultActiveKey+'';

		let isysladmins=false;
		let is_teacher=this.props&&this.props.current_user&&this.props.current_user.is_teacher?this.props.current_user.is_teacher:false;
		const professional_certification=this.props&&this.props.current_user&&this.props.current_user.professional_certification?this.props.current_user.professional_certification:false;
	  try {
			if(this.props){
				if(this.props.current_user){
					if(this.props.current_user.admin){
						isysladmins=true;
					}
					else if(this.props.current_user.business){
						isysladmins=true;
					}
				}
			}


			if(is_teacher===false){
				if(this.props.current_user.user_identity !=="学生"){
					//专业人士
					is_teacher=true
				}
			}
		}catch (e) {

		}

		const contents = (
			<div  className="questiontypes" style={{
				width:'93px',
				height:'160px',
			}}>
				<p className="questiontype " onClick={()=>this.props.setdifficulty(null)}>全部</p>
				<p className="questiontypeheng"></p>
				<p className="questiontype " onClick={()=>this.props.setdifficulty(1)}>简单</p>
				<p className="questiontypeheng"></p>
				<p className="questiontype "  onClick={()=>this.props.setdifficulty(2)}>适中</p>
				<p className="questiontypeheng"></p>
				<p className="questiontype "  onClick={()=>this.props.setdifficulty(3)}>困难</p>
				<p className="questiontypeheng"></p>
			</div>
		);

		if(defaultActiveKeybool===false){
			if(defaultActiveKeyss==="0"){
				defaultActiveKeys="0";
			}else {
				defaultActiveKeys="1";
			}
		}
    let auth_roles =this.props.auth_role;
		let Periofters = false;
		if (this.props) {
			if (this.props.current_user) {
				if (this.props.current_user.admin) {
					Periofters = true;
				}
				else if (this.props.current_user.business) {
					Periofters = true;
				}
				else if (this.props.current_user.is_shixun_marker) {
					Periofters = true;
				}
				else if (this.props.current_user.is_teacher) {
					Periofters = true;
				} else if (this.props.current_user.user_identity !== "学生") {
					Periofters = true;
				}
			}
		}

		return (
			<div className=" clearfix mt25">
				<div className="educontent mt10 pb20 w1200s">
					{
						mydisplay===true?
							<Certifiedprofessional {...this.props} {...this.state}  ModalCancelsy={this.mydisplayHidedel} />

							:""
					}
					{
						mydisplay===true||SendTop===true?
							<style>
								{
									`
									  body{
            overflow:hidden!important;
          }

									`
								}
							</style>

							:""
					}
					{SendTop===true?
						<SendTopicsModel paramsid={paramsid}  visible={SendTop} mypaper={false} {...this.state} {...this.props} submitInfos={(b,id)=>this.submitInfos(b,id)}></SendTopicsModel>:""
					}
					<div className="w1200ms contentparttit" style={{
						position: "relative",
					}}>
						<style>
							{
								`
								.contentparttit .ant-tabs-bar{
										margin: 0px 0px 0px 0px !important;
								}
								.contentparttit .ant-tabs-nav  .ant-tabs-tab{
								margin: 10px 10px 10px 0 !important;
								}
								.contentparttit .ant-tabs-nav .ant-tabs-ink-bar{
								width: 31px !important;
								left: 14px;
								}
								.ant-tabs-nav{
								z-index: 1000;
								}
								`
							}
						</style>


									<Tabs activeKey={defaultActiveKeys} onChange={(e)=>this.props.callback(e,true)}>
										<TabPane tab="公共" key="1">
										</TabPane>
										<TabPane tab="我的" key="0">
										</TabPane>
									</Tabs>

						<div className=" mt19" style={{
							position:"absolute",
							top: "0px",
							paddingLeft: "170px",
							width: "100%",
						}}>
							<style>
								{
									`
										
									
									.xaxisreverseorder .ant-input-wrapper .ant-input-group-addon .ant-input-lg {
								 height: 39px !important;
								 border: 1px solid #d9d9d9!important;
									 }
                 .sortinxdirection .ant-input-wrapper .ant-input-group-addon .ant-btn-lg  {
								 height: 39px !important;
								 border: 1px solid #d9d9d9!important;
									 }
                 
               
									.sortinxdirection .ant-input-group-addon{
									width: 48px !important;
									
									}
									
									.sortinxdirection .ant-input-lg {
  								  height: 41px;}
                 
                  .sortinxdirection .ant-popover{
                       top: 348px !important;
                   }
                   
									`
								}
							</style>
							<div className={Periofters===true?"sortinxdirection":"xaxisreverseorder"}>
								<Search
									style={{ width: "347px",marginRight:"60px",}}
									placeholder="请输入题目名称、内容"
									enterButton
									size="large"
									onInput={(e)=>this.props.setdatafunsval(e)}
									onSearch={ (value)=>this.props.setdatafuns(value)}
									value={this.props.keyword}
								/>

								{Periofters===true&&auth_roles===true?
										<div className="xaxisreverseorder" style={{
											width:"50%"
										}}>
											<a  onClick={()=>this.xinzenw('/problemset',auth_roles)}>
												<div className="newbutoonss">
													<p className="newbutoontess" >人工组卷</p>
												</div>
											</a>

											{/*<a  onClick={()=>this.xinzenw('/Integeneration')}>*/}
											{/*	<div className="newbutoonss">*/}
											{/*		<p className="newbutoontess" >智能组卷</p>*/}
											{/*	</div>*/}
											{/*</a>*/}

											{/*<a  onClick={()=>this.xinzenw('/problemset')}>*/}
											{/*	<div className="newbutoons mr39">*/}
											{/*		<p className="newbutoontess" >人工组卷</p>*/}
											{/*	</div>*/}
											{/*</a>*/}
										</div>
									:
									""
								}
							</div>

						</div>
					</div>
					{/*内容*/}
					{
						this.props.Contentdata.exams === undefined ||this.props.Contentdata.exams === null||this.props.Contentdata.exams.length===0 ?
							<div className=" w100s mb10"></div>
							:
							<div className=" w100s mb10" style={
								{
									position:"relative",
								}
							}>
								{
									defaultActiveKey===1||defaultActiveKey==="1"?
										<Contentquestionbank {...this.props} {...this.state}  ></Contentquestionbank>
										:""
								}
								{
									defaultActiveKey===0||defaultActiveKey==="0"?
										<Contentquestionbank {...this.props} {...this.state} ></Contentquestionbank>
										:""
								}
							</div>
					}


					<div className="minheight">
						{/*列表集合*/}
						<div className=" w100s">
							{
								this.props.booljupyterurls===true?
									<LoadingSpin></LoadingSpin>
									:
									this.props.Contentdata.exams === undefined ||this.props.Contentdata.exams === null||this.props.Contentdata.exams.length===0?
										<NoneDatas></NoneDatas>


										: this.props.Contentdata.exams.map((object, index) => {
											return (
												<Listjihe {...this.state} {...this.props} items={object} key={index}
																	Testpapereditor={(e)=>this.Testpapereditor(e)}
																	showmodels={(e)=>this.showmodels(e)}
																	showmodelysl={(e)=>this.showmodelysl(e)}
																	Isitapopup={this.props.Isitapopup}
																	showmodelsInaudit={(e)=>this.props.showmodelsInaudit(e)}
																	submitInfos={(b,id)=>this.submitInfos(b,id)}
																	auth_role={this.props.auth_role}
												>

												</Listjihe>
											)
										})}



						</div>

					</div>


			</div>
				</div>
		)

	}



}
export default Contentpart
