import {
    ChangeDetectionStrategy,
    Component,
    Input,
    OnChanges,
    SimpleChanges,
} from '@angular/core';
import { ViewType } from '@app/shared/enumerators/flight-request-type.enum';
import { FlightModel, getFirstLeg, Leg } from '@app/shared/models-legacy';
import {
    arrivalBlockOnCaption,
    arrivalBlockOnTimes,
    departureBlockOffCaption,
    departureBlockOffTimes,
} from '@app/utils/times';
import { OldAirportVisibilityService } from '@shared/services/old-airport-visibility.service';

@Component({
    selector: 'flight-board-details',
    templateUrl: './flight-board-details.component.html',
    styleUrls: [
        './flight-board-details.component.scss',
        './flight-board-details.component.mobile.scss',
    ],
    changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FlightBoardDetailsComponent implements OnChanges {
    @Input() flight: FlightModel;
    @Input() leg: Leg;
    @Input() connected: boolean;

    firstLeg: Leg;
    ViewType = ViewType;

    constructor(private airportService: OldAirportVisibilityService) {}

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

    get departureStationForTerminalChange() {
        return this.airportService.departureStationForTerminalChange(this.leg);
    }

    get arrivalStationForTerminalChange() {
        return this.airportService.arrivalStationForTerminalChange(this.leg);
    }

    get departureBlockOffTimes() {
        return departureBlockOffTimes(this.leg.departure._times);
    }

    get departureBlockOffCaption() {
        return departureBlockOffCaption(this.leg.departure._times);
    }

    get arrivalBlockOnTimes() {
        return arrivalBlockOnTimes(this.leg.arrival._times);
    }

    get arrivalBlockOnCaption() {
        return arrivalBlockOnCaption(this.leg.arrival._times);
    }
}
