import {
    ChangeDetectionStrategy,
    Component,
    EventEmitter,
    Input,
    Output,
} from '@angular/core';
import { FlightModel } from '@shared/models-legacy';
import { compareFlightsByPId } from '@utils/flight/p-id';

@Component({
    selector: 'online-board-flights-mini-list',
    templateUrl: './online-board-flights-mini-list.component.html',
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class OnlineBoardFlightsMiniListComponent {
    @Input() flight: FlightModel;
    @Input('flights') flightsLegacy: FlightModel[] = [];

    @Output() open = new EventEmitter<FlightModel>();

    public openFlight(flight?: FlightModel) {
        if (!flight) {
            return;
        }

        this.open.emit(flight);
    }

    public isFlightSelected(flight: FlightModel) {
        if (this.flights.length === 1) {
            return false;
        }

        return compareFlightsByPId(this.flight as any, flight as any);
    }

    get flights() {
        return this.flightsLegacy.length ? this.flightsLegacy : [this.flight];
    }
}
