import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { DictionariesService } from '@modules/components/page-filters/services/dictionaries-service';

@Component({
    selector: 'meta-base',
    template: '',
})
export abstract class MetaBaseComponent implements OnInit {
    title = '';
    description = '';

    protected paramsName = 'params';

    protected constructor(
        protected route: ActivatedRoute,
        protected dictionaries: DictionariesService,
    ) {}

    protected abstract translateTitle(params: string): string;
    protected abstract translateDescription(params: string): string;

    protected getCity(cityCode: string) {
        return this.dictionaries.getCityOrAirport(cityCode)?.name || '';
    }

    ngOnInit(): void {
        this.route.params.subscribe({
            next: (routerParams) => {
                const params = routerParams[this.paramsName];

                this.dictionaries.ready$.then(() => {
                    this.title = this.translateTitle(params);
                    this.description = this.translateDescription(params);
                });
            },
        });
    }
}
