import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
import { FlightModel } from '@shared/models-legacy/flight.model';
import { getLegs, Leg } from '@app/shared/models-legacy';
import { ViewType } from '@app/shared/enumerators/flight-request-type.enum';

@Component({
    selector: 'board-details-header',
    templateUrl: './board-details-header.component.html',
    styleUrls: ['./board-details-header.component.scss'],
})
export class BoardDetailsHeaderComponent implements OnChanges {
    ViewType = ViewType;
    @Input() flight: FlightModel;
    changeRoute: boolean;
    reroute: boolean;
    legs: Leg[];

    ngOnChanges(changes: SimpleChanges) {
        if (this.flight && 'flight' in changes) {
            this.legs = getLegs(this.flight);
            this.changeRoute = this.legs.some((l) => l.changeRoute);
            this.reroute = this.legs.some((l) => l.reroute);
        }
    }
}
