import {connect} from 'react-redux';
import CheckBody from '@components/CheckBody';
import {getModule,getInitData} from '@store/async-actions/fetchModules.js';
import {HIDE,RESET,SETDROPSHOW,ISREAD,SEARCH_DROP_LOCATION,MODI_LOADING} from '@store/types/homePage.js';
import {SELECTSEARCHDATA} from "@store/types/checkBody";
import {billing} from '@store/async-actions/pushMessage';
import {filterDataArr} from '@utils/tools.js';

function mapStateToProps(state){ 
  const {homePage,mainSuit,checkBody} = state;
  const hasMain = filterDataArr(mainSuit.saveText);//||mainSuit.data.length;
  return {
    data:checkBody.data,
    defaultShowAll:checkBody.showAll,
    isEmpty:checkBody.isEmpty,
    update:checkBody.update,   //用于触发更新
    showArr:homePage.showDrop,
    totalHide:homePage.totalHide,
    saveText:checkBody.saveText,
    searchData:checkBody.searchData,    //延迟搜索结果
    hasMain,//主诉选中的数据
    focusTextIndex:checkBody.focusIndex,    //聚焦的自由文本标签index
    span:checkBody.span,
    searchInEnd:checkBody.searchInEnd,      //是否在搜索末尾插入结果
    selecteds:checkBody.selecteds,       //普通多选选中状态
    boxTop:state.homePage.boxTop,
    boxLeft:state.homePage.boxLeft,
    importLabel:checkBody.importLabel,    //需高亮的标签id
  }
}

function mapDispatchToProps(dispatch,state){
  return {
    getInit(){
      dispatch({type:MODI_LOADING,flag:true});
      dispatch(getInitData());
    },
    fetchModules(param){
      const {id,name,index,span,searchInEnd} = param;
      getModule(id).then((res)=>{
        if(res.data.code=='0'){
          dispatch({
            type:SELECTSEARCHDATA,
            index,
            name,
            data: res.data.data,
            span,
            isReplace:false,
            searchInEnd
          })
          dispatch({
            type:ISREAD
          })
        }
      });
    },
    //右侧推送
    fetchPushInfos(){
      //调右侧推送
      dispatch(billing());
    },
    getSearchLocation(top,left){
      dispatch({
        type:SEARCH_DROP_LOCATION,
        top:top,
        left:left,
        dis:0
      })
    }
  }
}

const CheckBodyCont = connect(mapStateToProps,mapDispatchToProps)(CheckBody);

export default CheckBodyCont;