import {
    ChangeDetectionStrategy,
    Component,
    Input,
    OnChanges,
    SimpleChanges,
} from '@angular/core';
import {
    FlightModel,
    getFirstLeg,
    getLastLeg,
    IArrivalStation,
    IDepartureStation,
} from '@app/shared/models-legacy';
@Component({
    selector: 'flights-details-list-flight',
    templateUrl: './flights-details-list-flight.component.html',
    styleUrls: ['./flights-details-list-flight.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FlightsDetailsListFlightComponent implements OnChanges {
    @Input() flight: FlightModel;
    @Input() flightDate: any;
    @Input() isBoard = false;
    @Input() isSchedule = false;

    arrival: IArrivalStation;
    departure: IDepartureStation;

    ngOnChanges(changes: SimpleChanges) {
        if (this.flight && 'flight' in changes) {
            this.arrival = getLastLeg(this.flight).arrival;
            this.departure = getFirstLeg(this.flight).departure;
        }
    }
}
