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-arrival-meta-tags',
    templateUrl: './online-board-arrival-meta-tags.component.html',
})
export class OnlineBoardArrivalMetaTagsComponent implements OnInit {
    title = '';
    description = '';

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

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

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