import { Component, OnInit, ChangeDetectionStrategy, Input, EventEmitter, Output } from '@angular/core';
import { OrderItemListItemDTO } from '@swagger/oms';
import { Group } from 'apps/sales/src/app/utils';
import { ShelfNavigationService } from '../../shared/services';

@Component({
  selector: 'app-search-result-group',
  templateUrl: 'search-result-group.component.html',
  styleUrls: ['search-result-group.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SearchResultGroupComponent implements OnInit {
  @Input()
  group: Group<string, OrderItemListItemDTO>;

  @Output()
  selectOrderItemListItem = new EventEmitter<OrderItemListItemDTO>();

  byOrderNumberFn = (item: OrderItemListItemDTO) => item.orderNumber;

  byProcessingStatusFn = (item: OrderItemListItemDTO) => item.processingStatus;

  byCompartmentCodeFn = (item: OrderItemListItemDTO) => item.compartmentCode;

  constructor(private navigationFacade: ShelfNavigationService) {}

  ngOnInit() {}

  navigateToDetails(orderItem: OrderItemListItemDTO) {
    this.navigationFacade.navigateToDetails(orderItem);
  }
}
