import React from "react";
import constants from "./MultiSelect.actionConstants";

let multiSelectStateReducers = function (state, action) {
  let initialState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
    list: [],
    selectedSuggestions: [],
    filteredOptions: [],
    searchString: ""
  };
  let stateJson = initialState;
  let actionType = action.type;
  let data = action.data;

  switch (actionType) {
    case constants.ON_MULTISELECT_ADD:
      stateJson = { ...data
      };

    case constants.ON_MULTISELECT_UPDATE_SELECTED_VALUES:
      stateJson = { ...data
      };
      return stateJson;

    case constants.ON_MULTISELECT_SELECT:
      stateJson = { ...data
      };
      return stateJson;

    case constants.ON_MULTISELECT_REMOVE:
      stateJson = { ...data
      };
      return stateJson;

    case constants.ON_MULTISELECT_SEARCH:
      stateJson = { ...data
      }; //stateJson.filteredOptions= data

      return stateJson;

    case constants.ON_MULTISELECT_SELECT_ALL:
      stateJson = { ...data
      };
      return stateJson;

    case constants.ON_MULTISELECT_REMOVE_ALL:
      stateJson = { ...data
      };
      return stateJson;

    default:
      return stateJson;
  }
};

export default multiSelectStateReducers;