import { Component, Input } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MetaBaseComponent } from '@components/meta-base/meta-base.component';
import { DictionariesService } from '@modules/components/page-filters/services/dictionaries-service';
import { TranslatePipe } from '@ngx-translate/core';
import { OnlineBoardUrlParserService } from '@online-board/services/url/url-parser.service';
import { DateTransformerService } from '@shared/services/date/date-transformer.service';
import { IFlight } from '@typings/flight/flight';

@Component({
    selector: 'online-board-flight-details-meta-tags',
    templateUrl: './flight-details-meta-tags.component.html',
})
export class OnlineBoardFlightDetailsMetaTagsComponent extends MetaBaseComponent {
    @Input() flight: IFlight;

    constructor(
        protected route: ActivatedRoute,
        protected dictionaries: DictionariesService,
        private translatePipe: TranslatePipe,
        private urlService: OnlineBoardUrlParserService,
        private dateService: DateTransformerService,
    ) {
        super(route, dictionaries);
    }

    private translate(tag: 'TITLE' | 'DESCRIPTION', params: string) {
        const { flightNumber, carrier, date } =
            this.urlService.parseFlightId(params);

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

        return this.translatePipe.transform(`SEO.BOARD.FLIGHT-DETAILS.${tag}`, {
            flightNumber: `${carrier} ${flightNumber}`,
            date: transformedDate,
        });
    }

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

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