import { PossibleFilterValue } from './types';

const formatValue = (value: PossibleFilterValue): string => {
  if (Array.isArray(value)) {
    return value.join(', ');
  }

  if (typeof value === 'string') return value;

  if (typeof value === 'object') {
    return `${value?.startDate} - ${value?.endDate}`;
  }

  return '';
};

const getDefaultValue = (value: PossibleFilterValue): PossibleFilterValue => {
  if (Array.isArray(value)) return [];

  if (typeof value === 'string') return '';

  if (typeof value === 'object') return {};

  return value;
};

const isDefaultValue = (value: PossibleFilterValue) => {
  if (Array.isArray(value)) return value.length === 0;

  if (typeof value === 'string') return value.length === 0;

  if (typeof value === 'object')
    return Object.values(value).every(v => v === undefined);

  return value === undefined;
};

export { formatValue, getDefaultValue, isDefaultValue };
