import { Pipe, PipeTransform } from '@angular/core';
import { getFlights } from '../models-legacy';
import { FlightModel } from '../models-legacy/flight.model';

@Pipe({
    name: 'flightNumber',
})
export class FlightNumberPipe implements PipeTransform {
    transform(flight?: FlightModel): string {
        if (!flight) return '';
        return getFlights(flight)
            .filter((f) => !!f.flightId)
            .map((f) => `${f.flightId.carrier}\u00a0${f.flightId.flightNumber}${f.flightId.suffix}`)
            .join(', ');
    }
}
