import React from 'react';
import { connect } from 'react-redux';
import Treat from '@components/Treat';
import { SELECT_DRUG, SET_OTHER_DRUG, SET_DRUG_INFO, CLEAR_DRUG_INFO,HIDE_TREAT, CLEAR_TREAT, SHOW_DRUG_INFO, HIDE_DRUG_INFO, CHANGE_REACT,  DEL_REACT, SET_FOLLOW_UP } from '@store/types/treat.js';
import { getInstroduce, getRecommendBasic, getInstroduceMore, commonTreatAddToAdvice, saveAllAdverseReactions, setAllFollowUp } from '@store/async-actions/treat';
import { ADD_SCHEME } from '@store/types/pushMessage.js'
import { showDrugInfo } from '../store/actions/treat';


function mapStateToProps(state){
    const { treatment, generalTreat, surgeryTreat, drugHistory, adversReactionList, treatDesc, drugInfo, showDrugInfo, treatItem , drugInfoList, followUp, hasFollowUp} = state.treat;
    return {
        treatment: treatment,
        generalTreat: generalTreat,
        surgeryTreat: surgeryTreat,
        drugHistory: drugHistory,
        adversReactionList: adversReactionList,
        treatDesc: treatDesc,
        drugInfo: drugInfo,
        showDrug: showDrugInfo,
        treatItem: treatItem,
        drugInfoList: drugInfoList,   //药品说明书列表（查询多个药品说明书）
        followUp: followUp,
        hasFollowUp: hasFollowUp,
        isRead:state.homePage.isRead,
        

    }
}
 
function mapDispatchToProps(dispatch) {
    return {
        changeReact: (it, index) => {
            dispatch({type: CHANGE_REACT, it, index})
        },
      
        selectDrug: (index, ii)=>{
            dispatch ({
                type: SELECT_DRUG,
                index: index,
                ii: ii
            })
        },
        setOtherRecommend: (item, index) => {
            dispatch ({
                type: SET_OTHER_DRUG,
                item: item,
                index: index,
            })
            //推荐依据不展示
            // dispatch(getRecommendBasic(item))
        },
        setDrugInfo: (item, type, position) => {
            dispatch(getInstroduce(item, type, position));
        },
        hideTreat: () => {
            dispatch({
                type: HIDE_TREAT
            })
        },
        clearTreat: () => {
            dispatch({
                type: CLEAR_TREAT
            })
        },
        showDrugInfo: () => {
            dispatch({
                type: SHOW_DRUG_INFO
            })
        },
        hideDrugInfo: () =>{
            dispatch({
                type: CLEAR_DRUG_INFO
            })
            dispatch({
                type: HIDE_DRUG_INFO
            })
        },
        addScheme: (title, treatment) => {
            dispatch({
                type: ADD_SCHEME,
                title: title,
                treatment: treatment
            })
            dispatch(commonTreatAddToAdvice())
        },
        //保存所有诊断的不良反应
        saveAllAdverseReaction: (item) => {
            dispatch(saveAllAdverseReactions(item))
        },
        //保存全部回访时间
        setAllFollowUp: (item) => {
            dispatch(setAllFollowUp(item))
        },
        //查询多条药品说明数据（添加数据用）
        setDrugInfoMore:(drugIdList) => {
            dispatch(getInstroduceMore(drugIdList));
        },
        setFollowUp: (followUp) => {
            dispatch({
                type: SET_FOLLOW_UP,
                followUp: followUp
            })
        },
        hideDrugInfoMore: () =>{
            dispatch({
                type: HIDE_DRUG_INFO
            })
        }
    }
}

const TreatContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(Treat)

export default TreatContainer;