import { SelectFilter } from 'apps/sales/src/app/modules/filter';
import { flatten } from 'apps/sales/src/app/shared/utils';

export function selectFiltersToFiltersDictionary(selectFilters: SelectFilter[]): { [key: string]: string } {
  if (!selectFilters) {
    return {};
  }

  const result = selectFilters
    .map((selectFilter) => {
      const flattened = flatten(selectFilter.options, 'options').filter((o) => !!o.selected);
      return { [selectFilter.key]: flattened.map((f) => f.id).join(';') };
    })
    .reduce((acc, curr) => ({ ...acc, ...curr }), {});

  return result;
}
