import { Pipe, PipeTransform } from '@angular/core';
import { OrderItemListItemDTO } from '@swagger/oms';

@Pipe({
  name: 'coverCompartmentCode',
})
export class CoverCompartmentCodePipe implements PipeTransform {
  transform(item: OrderItemListItemDTO): string {
    const compartmentCodeSplit = item.compartmentCode.split('_');
    compartmentCodeSplit.shift();
    const compartmentCode = compartmentCodeSplit.join('_');

    if (!!item.compartmentInfo) {
      return `${compartmentCode}_${item.compartmentInfo}`;
    }
    return compartmentCode;
  }
}
