import React, { Component } from "react";
import { Tabs, Input, } from "antd";
import './../questioncss/questioncom.css';
import NoneDatas from '../component/NoneDatas';
import LoadingSpin from '../../../common/LoadingSpin';
import Contentquestionbank from "./Contentquestionbank";
import Listjihe from "./Listjihe";
import Certifiedprofessional from "../../modals/Certifiedprofessional";
import QuestionModalPicture from '../component/QuestionModalPicture'
const { TabPane } = Tabs;
const Search = Input.Search;
class Contentpart extends Component {
	constructor(props) {
		super(props);
		this.state = {
			page: 1,
			chakanjiexibool: false,
			mydisplay: false,
			occupation: 2,
			url: "",
			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
		})
		this.props.callback(this.props.defaultActiveKey);
	}
	handleShowUploadImage = (url) => {
		this.setState({
			url: url
		})
	}
	handleClose = () => {
		this.setState({
			url: '',
		})
	}

	chakanjiexibool = (index) => {
		//查看解析
		this.props.chakanjiexibool(index);
	}

	showmodels = (e) => {
		//设为公开
		this.props.showmodels(e)
	}

	showmodelsInaudit = (e) => {
		this.props.showmodelsInaudit(e)
	}

	showmodelysl = (e) => {
		this.props.showmodelysl(e)
	}

	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;
			var 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) {

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

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

	xinzenw = (e) => {
		// //只限制了教师
		// if(this.props.current_user.professional_certification===false&&this.state.isysladmins===false){
		// 	this.HideAddcoursestypess(2);
		// 	return
		// }
		var urls = "";
		if (this.props.discipline_id) {
			// if(urls==="?"){
			//  urls=urls+`discipline_id=${this.props.discipline_id}`
			// }else {
			urls = urls + `&discipline_id=${this.props.discipline_id}`
			// }
		}
		if (this.props.sub_discipline_id) {
			// if(urls==="?"){
			// 	urls=urls+`sub_discipline_id=${this.props.sub_discipline_id}`
			// }else {
			urls = urls + `&sub_discipline_id=${this.props.sub_discipline_id}`
			// }
		}
		if (this.props.tag_discipline_id) {
			// if(urls==="?"){
			// 	urls=urls+`sub_discipline_id=${this.props.tag_discipline_id}`
			// }else {
			urls = urls + `&sub_discipline_id=${this.props.tag_discipline_id}`
			// }
		}
		if (this.props.difficulty) {
			// if(urls==="?"){
			// 	urls=urls+`difficulty=${this.props.difficulty}&`
			// }else {
			urls = urls + `&difficulty=${this.props.difficulty}`
			// }
		}
		if (this.props.item_type) {
			// if(urls==="?"){
			// 	urls=urls+`item_type=${this.props.item_type}`
			// }else {
			urls = urls + `&item_type=${this.props.item_type}`
			// }

		}

		this.props.history.push("/problemset/newitem?pages=" + this.props.pages + urls);

	}
	render() {
		let { page, mydisplay, url } = this.state;
		let { defaultActiveKey, item_type, booljupyterurls } = this.props;
		const 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 (is_teacher === false) {
				if (this.props.current_user.user_identity !== "学生") {
					//专业人士
					is_teacher = true
				}
			}
			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;
					}
				}
			}
		} catch (e) {

		}

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

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

									`
								}
							</style>

							: ""
					}
					<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;
								}
								`
							}
						</style>

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

						<div className=" mt19" style={{
							position: "absolute",
							top: "0px",
							right: " 0px",
							paddingRight: "20px",
						}}>
							<style>
								{
									`
									
									.xaxisreverseorder .ant-input-group-addon{
									width: 48px !important;
									}
									.xaxisreverseorder .ant-input-group-addon .ant-btn-lg {
									 height: 38px !important;
								 border: 1px solid #d9d9d9!important;
									}
									
                  .xaxisreverseorder .ant-popover{
                       top: 30px !important;
                   }
                   
                   
                  .xaxisreverseorder .ant-popover-inner-content {
                   padding:0px !important;
                   }
                   
                   
									 
									`
								}
							</style>
							<div className="xaxisreverseorder">
								{
									this.props.Isitapopup && this.props.Isitapopup === "true" ?
										""
										:
										<a onClick={(e) => this.xinzenw(e)}>
											<div className="newbutoon">
												<p className="newbutoontes" >新增</p>
											</div>
										</a>
								}

								{
									this.props.Isitapopup && this.props.Isitapopup === "true" ?
										<Search
											style={{ marginRight: "0px" }}
											className={"xaxisreverseorder searchwidth"}
											placeholder="请输入题目名称、内容"
											enterButton
											size="large"
											onInput={(e) => this.props.setdatafunsval(e)}
											onSearch={(value) => this.props.setdatafuns(value)} />
										:
										<Search
											style={{ marginRight: "30px" }}
											className={"xaxisreverseorder searchwidth"}
											placeholder="请输入题目名称、内容"
											enterButton
											size="large"
											onInput={(e) => this.props.setdatafunsval(e)}
											onSearch={(value) => this.props.setdatafuns(value)} />
								}

							</div>

						</div>
					</div>
					{/*内容*/}
					{
						this.props.Contentdata.items === undefined || this.props.Contentdata.items === null || this.props.Contentdata.items.length === 0 ?
							<div className=" w100s mb10"></div>
							:
							<div className=" w100s mb10">
								{
									defaultActiveKey === 1 || defaultActiveKey === "1" ?
										<Contentquestionbank {...this.props} {...this.state} selectallquestionsonthispages={this.props.selectallquestionsonthispages} selectallquestionsonthispage={(bool) => this.props.selectallquestionsonthispage(bool)} ></Contentquestionbank>
										: ""
								}
								{
									defaultActiveKey === 0 || defaultActiveKey === "0" ?
										<Contentquestionbank {...this.props} {...this.state} selectallquestionsonthispages={this.props.selectallquestionsonthispages} selectallquestionsonthispage={(bool) => this.props.selectallquestionsonthispage(bool)}></Contentquestionbank>
										: ""
								}
							</div>
					}

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


										: this.props.Contentdata.items.map((object, index) => {
											return (
												<Listjihe {...this.state} {...this.props}
													defaultActiveKeys={defaultActiveKeys}
													Datacountbool={this.props.Datacountbool}
													Datacount={this.props.Datacount}
													Isitapopup={this.props.Isitapopup}
													chakanjiexiboolindex={this.props.chakanjiexiboolindex}
													chakanjiexibool={(keindex) => this.chakanjiexibool(keindex)}
													listjihe={index + 1}
													keindex={index}
													items={object}
													key={index}
													pages={this.props.pages}
													getitem_basketss={(id) => this.props.getitem_basketss(id)}
													getitem_baskets={(e) => this.props.getitem_baskets(e)}
													showmodels={(e) => this.showmodels(e)}
													showmodelysl={(e) => this.showmodelysl(e)}
													showmodelsInaudit={(e) => this.showmodelsInaudit(e)}
													handleShowUploadImage={(e) => this.handleShowUploadImage(e)}
													handleClose={() => this.handleClose()}
													setasprivates={(e) => this.props.setasprivates(e)}
												>

												</Listjihe>
											)
										})
							}
						</div>
					</div>
				</div>
			</div>
		)
	}
}
export default Contentpart
