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-route-title',
    templateUrl: './online-board-route-title.component.html',
})
export class OnlineBoardRouteTitleComponent 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.getRouteTitle(
                        data.urlParams.route,
                    );
                }
            },
        });
    }
}
