import {
    ChangeDetectionStrategy,
    Component,
    EventEmitter,
    Input,
    OnChanges,
    Output,
} from '@angular/core';
import { FlightLoadedState } from '@shared/enumerators';
import { DirectFlight, ITransition, Leg } from '@app/shared/models-legacy';
import { ISimpleFlight } from '@typings/flight/flight';

@Component({
    selector: 'board-flight-body',
    templateUrl: './board-flight-body.component.html',
    styleUrls: ['./board-flight-body.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BoardFlightBodyComponent implements OnChanges {
    @Input() flight: DirectFlight;
    FlightLoadedStates = FlightLoadedState;
    leg: Leg;
    transition: ITransition;

    @Output() toDetails = new EventEmitter<ISimpleFlight>();

    ngOnChanges() {
        this.leg = this.flight.leg;
        this.transition = this.leg.transition;
    }

    handleToDetailsEvent(flight: ISimpleFlight) {
        this.toDetails.emit(flight);
    }
}
