import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ScheduleTitleService } from '../../../../services/title.service';
import { IScheduleRouteData } from '@schedule/types';

@Component({
    selector: 'schedule-search-title',
    templateUrl: './schedule-search-title.component.html',
})
export class ScheduleSearchTitleComponent implements OnInit {
    title = '';

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

    ngOnInit() {
        this.route.data.subscribe(async (data: IScheduleRouteData) => {
            if (data.urlParams?.route.outbound) {
                this.title = await this.titleService.getSearchPageTitle(
                    data.urlParams.route.outbound,
                );
            }
        });
    }
}
