import { Pipe, PipeTransform } from '@angular/core';
import { TranslatePipe } from '@ngx-translate/core';
import { RouteTypeLegacy } from '../enumerators';
import { Transfer } from '../models-legacy';

@Pipe({
    name: 'transferType',
})
export class TransferTypePipe implements PipeTransform {
    constructor(private translate: TranslatePipe) {}
    transform(transfers: Transfer[], routeType: RouteTypeLegacy): string {
        if (!transfers || transfers.length === 0) {
            return '';
        }

        const pluralForms = {
            one: 'ONE',
            few: 'FEW',
            other: 'OTHER',
        };

        const plural = transfers.length === 1 ? pluralForms.one : transfers.length < 5 ? pluralForms.few : pluralForms.other;

        switch (routeType) {
            case RouteTypeLegacy.MultiLeg:
                return this.translate.transform(`SHARED.INTERMEDIATE-LANDING-PLURAL-${plural}`);
            case RouteTypeLegacy.Connecting:
                return this.translate.transform(`SHARED.FLIGHT-TRANSFER-PLURAL-${plural}`);
            case RouteTypeLegacy.Direct:
            default:
                return '';
        }
    }
}
