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

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

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