import React from "react";
import {connect} from "react-redux";
import Operation from "../components/Operation";
import {
    SHOW_PRINT_PREVIEW,
    CLOSE_PRINT_PREVIEW,
    SHOW_PREVIEW,
    CLOSE_PREVIEW,
    DIAG_SHOW
} from "../store/types/print";
import {saveMessage,clearMessages} from "../store/async-actions/print";
import {saveTemplateDetail} from '@store/async-actions/tabTemplate';
import {saveClickNum,getInitModules} from '@store/async-actions/homePage';
import {getOtherHisRecord} from '@store/async-actions/fetchModules';

// function mapStateToProps({print}) {
function mapStateToProps(state) {
    const {print,homePage} = state;
    return ({
        print,
        winWidth:homePage.windowWidth,
        chronicMagItem: state.diagnosticList.chronicMagItem,//慢病疾病
        chronicDesease:state.mainSuit.chronicDesease,//主诉存的慢病
    });
}

function mapDispatchToProps(dispatch) {
    return {
        showPrintPreview: () => {
            dispatch({
                type: SHOW_PRINT_PREVIEW
            });
        },
        closePrintPreview: () => {
            dispatch({
                type: CLOSE_PRINT_PREVIEW
            });
        },
        showPreview: () => {
            dispatch({
                type: SHOW_PREVIEW
            });
        },
        closePreview: () => {
            dispatch({
                type: CLOSE_PREVIEW
            });
        },
        save: () => {
            dispatch(saveClickNum);
            dispatch(() => saveMessage())
        },
        clear: (flag) => {
            clearMessages();
            dispatch(getOtherHisRecord());      //清除后重新获取其他史记录
            // 清除时如果是慢病模板则重新获取模板
            if(flag){
                dispatch(getInitModules);
            }
        },
        saveDataAll(val,sex){
          dispatch(saveTemplateDetail(val,sex))
        },
        diagShowTmp(bool){
          dispatch({
            type: DIAG_SHOW,
            data:bool
          });
        }
    };
}

const OperationComtainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(Operation);

export default OperationComtainer;