import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { FlightStatusLegacy } from '@app/shared/enumerators';
import { FlightModel, Leg, zeroDuration } from '@app/shared/models-legacy';

@Component({
    selector: 'route-status',
    templateUrl: './route-status.component.html',
    styleUrls: ['./route-status.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RouteStatusComponent {
    @Input() flight: FlightModel;
    @Input() leg: Leg;

    get inFlight() {
        return this.leg.status === FlightStatusLegacy.inFlight;
    }

    get finished() {
        return (
            this.leg.status == FlightStatusLegacy.landed ||
            this.leg.status == FlightStatusLegacy.arrived
        );
    }

    get starting() {
        return (
            this.leg.status == FlightStatusLegacy.scheduled ||
            this.leg.status == FlightStatusLegacy.delayed ||
            this.leg.status == FlightStatusLegacy.sent ||
            this.leg.status == FlightStatusLegacy.cancelled
        );
    }

    get remainingFlightDuration() {
        // Can be cases when flight is finished but remainingFlightDuration
        // isn't zeroDuration. So we need explicitly set it.
        if (this.finished) {
            return zeroDuration;
        }

        return this.leg.remainingFlightDuration;
    }

    get inFlightStatusClasses() {
        const almostFinished = this.leg.flightPercent > 98;

        return {
            description: true,
            'flight-route__in-flight-status': true,
            'flight-route__in-flight-status--right': almostFinished,
        };
    }
}
