import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { OnlineBoardTitleService } from '@online-board/services/title.service';
import { IOnlineBoardRouteData } from '@online-board/types';

@Component({
    selector: 'online-board-flight-number-title',
    templateUrl: './online-board-flight-number-title.component.html',
})
export class OnlineBoardFlightNumberTitleComponent implements OnInit {
    title = '';

    constructor(
        private route: ActivatedRoute,
        private titleService: OnlineBoardTitleService,
    ) {}

    ngOnInit() {
        this.route.data.subscribe({
            next: (data: IOnlineBoardRouteData) => {
                if (data.urlParams.flightNumber) {
                    this.title = this.titleService.getFlightNumberTitle(
                        data.urlParams.flightNumber,
                    );
                }
            },
        });
    }
}
