import { Directive, TemplateRef, ViewContainerRef } from '@angular/core';
import { DictionariesService } from '@app/modules/components/page-filters/services/dictionaries-service';
import { LocalizationService } from '../services';

@Directive({
    selector: '[localisationReady]',
})
export class LocalisationReadyDirective {
    constructor(
        private dictionaries: DictionariesService,
        private locale: LocalizationService,
        private templateRef: TemplateRef<any>,
        private viewContainer: ViewContainerRef,
    ) {}

    async ngOnInit() {
        await Promise.all([this.locale.ready$, this.dictionaries.ready$]);
        this.viewContainer.createEmbeddedView(this.templateRef);
    }
}
