import {connect} from 'react-redux';
import PreInIcss from '@components/PreInIcss';
import {getPreMsg} from '@store/async-actions/preIcss';
import { GET_PREC_LIST,SET_PREC_SHOW,SET_MOVE } from "@store/types/preIcss";
import {SETPRE,SETPREDATA} from "@store/types/homePage";

const mapStateToProps = function(state){//console.log(state)
  return {
    data:state.preIcss.preData,
    show:state.preIcss.preShow,
    windowHeight:state.homePage.windowHeight,
    isMove:state.preIcss.isMove
  }
}

const mapDispatchToProps = function(dispatch){
  return {
    setMove(flg){
      dispatch({type:SET_MOVE,isMove:flg})
    },
    showPreModal(){
      dispatch({type:SET_PREC_SHOW})
    },
    showPre(item){
      let preIcss = {},detail = item.detail
      if(detail){
        preIcss = {
          chief:detail.chiefComplaint?new Array(detail.chiefComplaint):[],
          current:detail.xbs?new Array(detail.xbs):[],
          other:detail.qts?new Array(detail.qts):[],
          checkBody:detail.supplement?detail.supplement:''
        }
      }
      dispatch({type:SETPREDATA,preData:preIcss,item:item});
      dispatch({type:SETPRE,show:true});
    },
    setPreData(){
      getPreMsg()
    }
  }
}

export default connect(mapStateToProps,mapDispatchToProps)(PreInIcss);