import { Injectable } from '@angular/core';
import { DictionariesService } from '@modules/components/page-filters/services/dictionaries-service';
import { TranslateService } from '@ngx-translate/core';
import { IScheduleRouteDirectionParams } from './url/types';

@Injectable()
export class ScheduleTitleService {
    constructor(
        private translateService: TranslateService,
        private dictionaries: DictionariesService,
    ) {}

    getStartPageTitle() {
        return 'SCHEDULE.TITLE';
    }

    async getSearchPageTitle(params: IScheduleRouteDirectionParams) {
        const titleBase = this.translateService.instant(
            'SCHEDULE.SCHEDULE-BY-ROUTE',
        );
        const route = await this.getSearchPageRouteTitle(params);

        return `${titleBase}: ${route}`;
    }

    async getSearchPageRouteTitle(params: IScheduleRouteDirectionParams) {
        const { arrival: arrivalCode, departure: departureCode } = params;

        const arrival = await this.dictionaries.getCityOrAirportNameAsync(
            arrivalCode,
        );
        const departure = await this.dictionaries.getCityOrAirportNameAsync(
            departureCode,
        );

        return `${departure} - ${arrival}`;
    }
}
