import React from 'react';
import { connect } from 'react-redux';
import DiagnosticList from '@components/DiagnosticList';
import { ADD_DIAGNOSTIC,  DEL_DIAGNOSTIC, UP_DIAGNOSTIC, DOWN_DIAGNOSTIC, GET_DIAGNOSTIC_STR, GET_IS_FIRST } from '@store/types/diagnosticList'; 
import { getSearchResult } from '@store/async-actions/diagnosticSearch';
import { getTreatResult } from '@store/async-actions/treat';
import { SHOW_TREAT } from '../store/types/treat';
import {billing, getTips} from '../store/async-actions/pushMessage';



function mapStateToProps(state) {
    return {
        list: state.diagnosticList.diagnosticList,
        treatment: state.treat.show,
        isFirst: state.diagnosticList.isFirst
    }
}

function mapDispatchToProps(dispatch) {
    return {
        delDiagnostic: (id) => {
            dispatch({
                type: DEL_DIAGNOSTIC,
                id: id
            });
            dispatch(getSearchResult)
            
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        upDiagnostic: (index, id) => {
            dispatch({
                type: UP_DIAGNOSTIC,
                index: index
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        downDiagnostic: (index, id) => {
            dispatch({
                type: DOWN_DIAGNOSTIC,
                index: index
            });
            dispatch({
                type: GET_DIAGNOSTIC_STR
            });
        },
        getSearchResult:() => {
            dispatch(getSearchResult)
        },
        showTreat: () => {
            dispatch({
                type: SHOW_TREAT,
            })
        },
        getTreatResult: (item) => {
            dispatch(getTreatResult(item))
        },
        getTips: (diagItem) => {
            dispatch(getTips(diagItem))
        },
        getBilling: () => {
            dispatch(billing)
        }
    }
}

const diagnosticListContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(DiagnosticList)

export default diagnosticListContainer;

