import React, { Component } from 'react';
import style from './index.less';
import info2 from './../img/info2.png';
import info3 from './../img/info3.png';
import $ from "jquery";

class AdverseReactions extends Component {
    constructor(props){
        super(props);
        this.state = {
            currentIndex: -1
        }
        this.handleMouseLeaveDrug = this.handleMouseLeaveDrug.bind(this);
        this.handleMouseLeaveImg = this.handleMouseLeaveImg.bind(this);
        this.setDrugInfo = this.setDrugInfo.bind(this);
      
    }
    changeReact(it, index, item) {
        this.props.changeReact(it, index);
    }
    handleMouseEnterDrug(index, item) {
        this.setState({
            currentIndex: index,
        })
    }
    handleMouseLeaveDrug() {
        this.setState({
            currentIndex: -1, 
        })
    }
    handleMouseEnterImg() {
        this.setState({
            hasEnterImg: true
        })
    }
    handleMouseLeaveImg() {
        this.setState({
            hasEnterImg: false
        })

     }
    setDrugInfo(item) {
        const { setDrugInfo } = this.props;
        setDrugInfo && setDrugInfo({name: item.name, type: 10, position: 6});
    }


    render() {
        const { icon, titleStyle,titleBg, filter, title,  adversReactionList, setDrugInfo } = this.props
        const  { currentIndex, hasEnterImg } = this.state
        return(
            <div className={style['last-treat-wrapper']}>
                <div className={style['last-treat-title-box']} style={titleStyle}></div>
                <div className={style['last-treat-title']} ><img className={style['last-treat-icon']} src={icon}/>{title}</div>
                {/* {console.log('adversReactionList', adversReactionList)} */}

                {adversReactionList.map((item, index) => {
                    return (<div className={style['adverse-reactions-item']} key={item.conceptId+item.name}>
                    <span className={style['last-treat-name-box']}>   
                        <span   
                                className={style['last-treat-big-name-box']} 
                                onMouseEnter={this.handleMouseEnterDrug.bind(this, index, item)}
                                onMouseLeave = {this.handleMouseLeaveDrug}
                        >
                            <span className={style['last-treat-big-name']} >{item.name}:
                                {<img className={style['info-img']}  
                                    title='点击i图标可查看详细说明'
                                    style ={currentIndex === index  ? {display: "inline-block"} : {display: "none"}}
                                    src={currentIndex === index ?(hasEnterImg ? info3 : info2 ): info2} 
                                    onMouseEnter={this.handleMouseEnterImg.bind(this)}
                                    onMouseLeave = {this.handleMouseLeaveImg}
                                    onClick={this.setDrugInfo.bind(this, item)}/>}
                            </span>
                        </span>
                        
                    </span>
                        {item.details.map((it, idx) => {
                            return <span className={`style['adverse-reactions-name'] ${it.value == 1 ? style['selectd']:''}`} key={item.conceptId + item.name + it.name}>
                                <input type="radio" checked={it.value == 1}  id={item.conceptId +item.name + it.name} onChange={this.changeReact.bind(this, it, index)}/>
                                <label for={item.conceptId +item.name + it.name}> {it.name} </label>
                                {/* {it.value==1 && <span className={style['adverse-reactions-recommend']}>(智能推荐)</span>} */}
                            </span>
                        })}
                    </div>)
                })}
            </div>
        )
    }

}

export default AdverseReactions;
