import {
  getOrderTypeFeature,
  RewardSelectionItem,
} from '@isa/checkout/data-access';

export const groupByOrderType = (
  items: RewardSelectionItem[],
): Map<string, RewardSelectionItem[]> => {
  return items.reduce((map, item) => {
    const orderType = getOrderTypeFeature(item.item.features) ?? 'Unbekannt';
    if (!map.has(orderType)) map.set(orderType, []);
    map.get(orderType)!.push(item);
    return map;
  }, new Map<string, RewardSelectionItem[]>());
};
