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

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

    constructor(
        private route: ActivatedRoute,
        private metaTagsService: OnlineBoardMetaTagsService,
    ) {}

    ngOnInit() {
        this.route.data.subscribe((data: IOnlineBoardRouteData) => {
            if (data.urlParams.flightNumber) {
                const metaTags = this.metaTagsService.getFlightNumberMetaTags(
                    data.urlParams.flightNumber,
                );

                this.title = metaTags.title;
                this.description = metaTags.description;
            }
        });
    }
}
