import React, {Component} from "react";

import { getImageUrl} from 'educoder';

import './../testioncss/testioncss.css';
import Certifiedprofessional from "../../modals/Certifiedprofessional";

class Listjihe extends Component {
	constructor(props) {
		super(props);
		this.state = {
			page:1,
			name:"单选题",
			nd:"简单",
			chakanjiexibool:false,
			mydisplay:false,
			occupation:2,
			isysladmins:false,
		}
	}
	//初始化
	componentDidMount(){
		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;
				}
			}
		}
		this.setState({
			isysladmins:isysladmins
		})
	}

	chakanjiexibool=()=>{
		if(this.state.chakanjiexibool===true){
			this.setState({
				chakanjiexibool:false
			})
		}else{
			this.setState({
				chakanjiexibool:true
			})
		}

	}
	//选用
	Selectingpracticaltraining=(id)=>{
		let data={
			item_ids:[id]
		}
		this.props.getitem_baskets(data);
	}
	//撤销
	Selectingpracticaltrainings=(id)=>{

		this.props.getitem_basketss(id);
	}
	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,
		})
	}

	gotoseesj=(id)=>{
		if(this.props.auth_role===false){
			this.HideAddcoursestypess(2);
			return
		}
		this.props.history.push(`/paperlibrary/see/${id}?defaultActiveKey=${this.props.defaultActiveKey}`);
	}


	render() {
		let {page,name,nd,chakanjiexibool,mydisplay}=this.state;
		let {defaultActiveKey,items}=this.props;

	   const names=	items&&items.name&&items.name;
	   const question_counts=items&&items.question_count&&items.question_count;
	   const total_scores =items&&items.total_score&&items.total_score;
	   const difficultys=items&&items.difficulty&&items.difficulty===1?"简单":items&&items.difficulty&&items.difficulty===2?"适中":items&&items.difficulty&&items.difficulty===3?"困难":""
		 const update_times=items&&items.update_time&&items.update_time;
	   const quotess =items&&items.quotes&&items.quotes;
	   const authors=items&&items.author&&items.author.name;

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

		let auth_roless=false;
		if(this.props.auth_role){
			if(this.props.auth_role===true){
				auth_roless=true;
			}else{
				auth_roless=false;

			}
		}else{
			auth_roless=false;

		}
		return (
			<div className={" borderwdsst  pd20 mb20 intermediatecenter  listjihecolor "} >
				{
					mydisplay===true?
						<Certifiedprofessional {...this.props} {...this.state}  ModalCancelsy={this.mydisplayHidedel} />

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

									`
							}
						</style>

						:""
				}
        <div className="sortinxdirection w100s">
           <div className="sjimg intermediatecenter">
						 <img src={getImageUrl("images/educoder/shijuans.png")}  className="imgtp"/>
					 </div>
           <div className="w100s  verticallayout ml20" >
						 {
							 auth_roless ?
								 <div className="w100s " > <a className="sjtitle xiaoshou " title={names} onClick={()=>this.gotoseesj(items.id)}><p className="maxnamewidth100s xiaoshou">{names}</p></a></div>
								 :
								 <div className="w100s " > <a className="sjtitle xiaoshout " title={names} ><p className="maxnamewidth100s xiaoshout">{names}</p></a></div>
						 }
						 <div className="w100s sortinxdirection mt9">
							 <p className="sjtitles">试题数：<span >{question_counts}</span></p>
							 <p className="sjtitles ml10">总分：<span >{total_scores}</span></p>
							 <p className="sjtitles ml10">难度：<span >{difficultys}</span></p>
						 </div>
						 <div className="w100s sortinxdirection mt11">
						 <div  className="w50s  sortinxdirection">
							 <p className='sjtitlesysl'>
								 更新时间：<span>{update_times}</span>

							 </p>
							 {
								 quotess===null||quotess===undefined||quotess===0?
									 ""
									 :
									 <p className='sjtitlesysl ml20 tknamelengs'>
										 使用次数：<span className="tknamelengs">{quotess}</span>
									 </p>
							 }

							 {
								 defaultActiveKey===1||defaultActiveKey==="1"?
									 <p className='sjtitlesysl ml20 tknamelengs'>
										 创建者：<span className="tknamelengs">{authors}</span>
									 </p>
									 :
									 ""
							 }


						 </div>

							 {
								 defaultActiveKey===0||defaultActiveKey==="0"?
							 <div  className="w50s  xaxisreverseorder">
								 {
									 auth_roless?
										 <p className="selection  xiaoshou" onClick={()=>this.props.submitInfos(true,items.id)}>
											 <span className=" lh30">发送至课堂</span>
										 </p>
										 :""
								 }
								 {
									 items&&items.edit_role&&items.edit_role===true?
										 <p className={auth_roless?"viewparsings  xiaoshou mr25 ":"viewparsings  xiaoshou  "}  onClick={()=>this.props.showmodelysl(items.id)}>
											 <i className="iconfont icon-shanchu1 font-17 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
											 <span>删除</span>
										 </p>
										 :""
								 }
								 {
									 this.props.Isitapopup&&this.props.Isitapopup==="true"?
										""
										:
										 (
											 items&&items.edit_role&&items.edit_role===true?
												 <p className="viewparsings  xiaoshou mr25 "  onClick={()=>this.props.Testpapereditor(items.id)}>
													 <i className="iconfont icon-bianji2 font-17 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
													 <span>编辑</span>
												 </p>
												 :""
										 )
								 }

								 {
											 items.public==true?
												 <p className="viewparsings   mr25 ">
													 <i className="iconfont  icon-dianjiliang font-13 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
													 <span>已公开</span>
												 </p>
												 :
												 items.apply===false?
													 <p className="viewparsings  xiaoshou mr25 " onClick={() => this.props.showmodels(items.id)}>
														 <i className="iconfont icon-gongkai font-17 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
														 <span>公开</span>
													 </p>
													 :
													 <p className="viewparsings  xiaoshou mr25" onClick={(e) => this.props.showmodelsInaudit(e)}>
														 <i className="iconfont icon-gongkai font-17 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
														 <span>公开审核中</span>
													 </p>
								 }
							 </div>
						    :
									 <div  className="w50s  xaxisreverseorder">
										 {
											 auth_roless?
												 <p className="selection  xiaoshou" onClick={()=>this.props.submitInfos(true,items.id)}>
													 <span className=" lh30">发送至课堂</span>
												 </p>
												 :''
										 }
										 {
										 items&&items.edit_role&&items.edit_role===true?
										 <p className={auth_roless?"viewparsings  xiaoshou mr25 ":"viewparsings  xiaoshou  "} onClick={()=>this.props.showmodelysl(items.id)}>
											 <i className="iconfont icon-shanchu1 font-17 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
											 <span>删除</span>
										 </p>:
										 ""
										 }
										 {
											 this.props.Isitapopup && this.props.Isitapopup === "true" ?
												 ""
												 :
												 (
												  items&&items.edit_role&&items.edit_role===true?
														 <a >
															 <p className="viewparsings  xiaoshou mr25 "  onClick={()=>this.props.Testpapereditor(items.id)}>
																 <i className="iconfont icon-bianji2 font-17 lg ml7 lh30 icontianjiadaohangcolors mr5"></i>
																 <span>编辑</span>
															 </p>
														 </a>
														 :""
												 )
										 }
									 </div>
							 }



						 </div>
					 </div>

					 <div className="sjfqks reversedirection" style={{
						 display: "none"
					 }}>
						 <div className="newbutoonss">
							 <p className="newbutoontess" >发起考试</p>
						 </div>
					 </div>

				</div>

			</div>
		)

	}

}
export default Listjihe;
