import { combineReducers } from 'redux';

function searchValue(state: any = {}, action: any) {
  if (action.type === 'ACTION_SEARCH_VALUE_CHANGE') {
    return action.searchValue;
  }
  return state;
}

function searchType(state: any = {}, action: any) {
  if (action.type === 'ACTION_SEARCH_TYPE_CHANGE') {
    return action.searchType;
  }
  return state;
}

function save(state: any = {}, action: any) {
  if (action.type === 'ACTION_SAVE_LEXITEM') {
    return {
      ...state,
      lexItem: action.lexItem,
    };
  }
  return state;
}

const searchReducer = combineReducers({ searchValue, searchType });
const rootReducer = combineReducers({ searchState: searchReducer, save });

export default rootReducer;
