import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MetaBaseComponent } from '@components/meta-base/meta-base.component';
import { TranslatePipe } from '@ngx-translate/core';
import { DictionariesService } from '@modules/components/page-filters/services/dictionaries-service';
import { ScheduleUrlParserService } from '@schedule/services/url/url-parser.service';
import { DateTransformerService } from '@shared/services/date/date-transformer.service';

@Component({
    selector: 'schedule-search-meta-tags',
    templateUrl: './schedule-search-meta-tags.component.html',
})
export class ScheduleSearchMetaTagsComponent extends MetaBaseComponent {
    constructor(
        protected route: ActivatedRoute,
        protected dictionaries: DictionariesService,
        private translatePipe: TranslatePipe,
        private urlService: ScheduleUrlParserService,
        private dateService: DateTransformerService,
    ) {
        super(route, dictionaries);
    }

    private translate(tag: 'TITLE' | 'DESCRIPTION', params: string) {
        const { arrival, departure, dateFrom } =
            this.urlService.parseRouteParams(params);

        const transformedDate = this.dateService.toString(dateFrom);

        return this.translatePipe.transform(`SEO.SCHEDULE.SEARCH.${tag}`, {
            arrivalCity: this.getCity(arrival),
            departureCity: this.getCity(departure),
            date: transformedDate,
        });
    }

    protected translateTitle(params: string): string {
        return this.translate('TITLE', params);
    }

    protected translateDescription(params: string): string {
        return this.translate('DESCRIPTION', params);
    }
}
