import { Component, Input } from '@angular/core';
import { ViewType } from '@app/shared/enumerators/flight-request-type.enum';
import { ArrivalTimesModel, DepartureTimesModel, Leg } from '@app/shared/models-legacy';
import { StationProperty } from '../timeline/timeline.component';
const defaults = {} as ArrivalTimesModel | DepartureTimesModel;
@Component({
    selector: 'flight-brief',
    templateUrl: './flight-brief.component.html',
    styleUrls: ['./flight-brief.component.scss'],
})
export class FlightBriefComponent {
    @Input() legs: Leg[];
    @Input() canChange = false;
    viewType: ViewType;
    /// returns latest or scheduled in case the time can change
    /// returns scheduled           in case the time can not change
    getLatest(leg: Leg, property: StationProperty) {
        const { latest, scheduled } = this.getTimes(leg, property);
        return this.canChange ? latest || scheduled : scheduled;
    }

    /// returns scheduled           in case the time can change
    /// returns undefined           in case the time can not change
    getBaseline(leg: Leg, property: StationProperty) {
        if (!this.canChange) return;
        const { scheduled } = this.getTimes(leg, property);
        return scheduled;
    }

    getType() {
        return this.canChange ? 'actual' : 'scheduled';
    }

    private getTimes(leg: Leg, property: StationProperty) {
        if (!leg) return defaults;
        return leg[property]?.times || defaults;
    }
}
