import {
    ChangeDetectionStrategy,
    Component,
    Input,
    OnChanges,
    SimpleChanges,
    ViewEncapsulation,
} from '@angular/core';
import { IStation } from '@app/shared/models-legacy';
import { airports } from '@app/shared/services/airports-data.service';

@Component({
    selector: 'terminal-link',
    templateUrl: './terminal-link.component.html',
    styleUrls: ['./terminal-link.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush,
    encapsulation: ViewEncapsulation.None,
})
export class TerminalLinkComponent implements OnChanges {
    @Input() station: IStation;
    @Input() onlyTerminal = false;
    @Input() oldValue = false;

    url?: string;
    ngOnChanges(changes: SimpleChanges) {
        if (this.station && 'station' in changes) {
            this.url = airports[this.station.latest?.airportCode];
        }
    }

    get classes() {
        return {
            'terminal-link': true,
            'terminal-link--old': this.oldValue,
        };
    }
}
