import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { FlightModel, getFirstLeg, Leg } from '@app/shared/models-legacy';
import { IAlign } from '@typings/common/align';

@Component({
    selector: 'operator-logo-and-model',
    templateUrl: './operator-logo-and-model.component.html',
    styleUrls: ['./operator-logo-and-model.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
    encapsulation: ViewEncapsulation.None,
})
export class OperatorLogoAndModelComponent implements OnChanges {
    @Input() flight: FlightModel;
    @Input() showModel = true;
    @Input() round = false;
    @Input() modelAlign: IAlign = 'left';
    leg: Leg;

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

    get modelClasses() {
        return {
            'aircraft-name': true,
            [`aircraft-name--${this.modelAlign}`]: this.modelAlign !== 'left',
        };
    }
}
