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

@Pipe({
    name: 'duration',
})
export class DurationPipe implements PipeTransform {
    constructor(private translate: TranslatePipe) {}

    transform(value?: Duration): string {
        if (!value) return '';

        const { days, hours = 0, minutes = 0 } = value;

        if (days < 0 || hours < 0 || minutes < 0) {
            return this.translate.transform('FLIGHT-STATUSES.Unknown');
        }

        const $days = days ? `${days}${this.translate.transform('SHARED.SHORT-DAY')} ` : '';

        return `${$days}${hours}${this.translate.transform('SHARED.SHORT-HOUR')} ${minutes}${this.translate.transform('SHARED.SHORT-MIN')}`;
    }
}
