import { Pipe, PipeTransform } from '@angular/core';
import { groupBy } from './group-by';
import { Group } from './group';

/**
 * @deprecated Use `GroupByPipe` from `@sahred/pipes/group-by` instead.
 */
@Pipe({
  name: 'groupBy',
  standalone: true,
  pure: true,
})
export class GroupByPipe implements PipeTransform {
  transform<TItem, TGroup>(value: TItem[], selectGroup: (item: TItem) => TGroup): Group<TGroup, TItem>[] {
    if (typeof selectGroup !== 'function') {
      console.warn(`Function selectGroup is required.`);
      return [];
    }
    return groupBy(value, selectGroup);
  }
}
