import React from 'react';
import { connect } from 'react-redux';
import {
  SHOW_SEARCH,
  HIDE_SEARCH,
  SHOW_TCM_SEARCH,
  HIDE_TCM_SEARCH,
  GET_SEARCH_RESULT,
  SHOWNODATATEXT,
} from '@store/types/diagnosticSearch';
import { getSearchResult, getSearchList } from '@store/async-actions/diagnosticSearch';
import DiagResultSearch from '@components/DiagResultSearch';

function mapStateToProps(state) {
    return {
      show: state.diagnosticSearch.show,
      showTcm: state.diagnosticSearch.showTcm,
      showSym:state.diagnosticSearch.showSym,
      searchValue: state.diagnosticSearch.searchValue,
      searchResult: state.diagnosticSearch.searchResult,
      isShowNoDataInfo: state.diagnosticSearch.isShowNoDataInfo,
    };
}

function mapDispatchToProps(dispatch) {
    return {
        showSearch:()=>{
            dispatch({
                type: SHOW_SEARCH
            })
        },
        hideSearch:()=>{
            dispatch({
                type: HIDE_SEARCH
            })
        },
        showTcmSearch:()=>{
            dispatch({
                type: SHOW_TCM_SEARCH
            })
        },
        hideTcmSearch:()=>{
            dispatch({
                type: HIDE_TCM_SEARCH
            })
        },
        showSymSearch:(flag)=>{
            dispatch({
                type: 'SHOW_SYM_SEARCH',
                show:flag
            })
        },
        clearSearchResult: ()=>{
            dispatch({
                type: GET_SEARCH_RESULT,
                searchResult: []
            })
        },
        handleChangeValue: (val, isClear)=>{
            if(isClear === 'clear'||val=='') {
              dispatch({
                type: SHOWNODATATEXT,
                isShowNoDataInfo: false
              });  
            }
            dispatch(getSearchList(val))
        }
    }
}

const DiagnosticSearchContainer = connect(
    mapStateToProps,
    mapDispatchToProps
)(DiagResultSearch);

export default DiagnosticSearchContainer
