export const normalizeSearchRangeParams = (params = {}, rangeMap = {}) => {
  const values = { ...params };

  Object.entries(rangeMap).forEach(([rangeProp, mapping]) => {
    const [startProp, endProp, startSuffix = '00:00:00', endSuffix = '23:59:59'] = Array.isArray(
      mapping
    )
      ? mapping
      : [mapping.startProp, mapping.endProp, mapping.startSuffix, mapping.endSuffix];

    const range = values[rangeProp];
    if (Array.isArray(range) && range.length === 2) {
      values[startProp] = range[0] ? `${range[0]} ${startSuffix}` : undefined;
      values[endProp] = range[1] ? `${range[1]} ${endSuffix}` : undefined;
    }

    delete values[rangeProp];
  });

  Object.keys(values).forEach(key => {
    if (values[key] === undefined || values[key] === null || values[key] === '') {
      delete values[key];
    }
  });

  return values;
};
