import _ from "lodash";
import { initialLocalFilters } from ".";

const _groupAdapter = (groupBy: any[]) => {
  return groupBy.map((g) => ({ field: g.value, dir: "asc" }));
};

export const setDataStateWithCustom = ({ dataFilters, dataState }: any) => {
  const eDataState = _.cloneDeep(dataState);
  eDataState.group = dataFilters?.groupBy?.length
    ? _groupAdapter(dataFilters.groupBy)
    : dataFilters?.defaultGroup;
  eDataState.sort = dataFilters?.sort ?? dataFilters?.defaultSort;
  eDataState.skip = dataFilters?.skip ?? dataFilters?.defaultSkip;
  eDataState.take = dataFilters?.take ?? dataFilters?.defaultTake;
  eDataState.filter = initialLocalFilters;

  return eDataState;
};