import { Component, EventEmitter, Inject, Input, Output } from '@angular/core';
import { ViewType } from '@app/shared/enumerators/flight-request-type.enum';
import { FlightLoadedState, RouteTypeLegacy } from '@shared/enumerators';
import {
    AppSettings,
    FlightModel,
    getLegs,
    ScheduleItemModel,
} from '@shared/models-legacy';
import { APP_SETTINGS } from '@shared/services';
import { IFlight } from '../../../../../../../typings/flight/flight';

@Component({
    selector: 'schedule-flight-details-view',
    templateUrl: './schedule-flight-details-view.component.html',
    styleUrls: ['./schedule-flight-details-view.component.scss'],
})
export class ScheduleFlightDetailsViewComponent {
    @Input() flight: FlightModel;
    @Input() flights: FlightModel[];
    @Input() schedule: ScheduleItemModel[];
    @Input() disabledDates: Date[];

    @Input() flightsLoading: boolean;
    @Input() detailsLoading: boolean;

    @Output() toScheduleDate = new EventEmitter<Date>();
    @Output() toFlightDetails = new EventEmitter<IFlight>();

    FlightLoadedStates = FlightLoadedState;
    RouteType = RouteTypeLegacy;
    ViewType = ViewType;
    getLegs = getLegs;

    constructor(@Inject(APP_SETTINGS) public settings: AppSettings) {}

    get isConnectingFlight() {
        return this.flights.length > 1;
    }

    get legs() {
        return getLegs(this.flight);
    }

    open(flight: IFlight) {
        this.toFlightDetails.emit(flight);
    }

    handleDateChanged(date: Date) {
        this.toScheduleDate.emit(date);
    }
}
