import { Directive, ElementRef, HostListener, Input, Renderer } from '@angular/core'

import { SharedService }                                        from '../services/svc.shared'

@Directive({ selector: '[trnsl]' })

export class TranslateDirective {

    @Input() trnsl: string;
    observable: any;

    subscriptions: any;

    constructor(
        el: ElementRef,
        renderer: Renderer,
        _shared: SharedService
    ) {

        // this.subscriptions = _shared.translate$.subscribe(response => {
        //      this.observable = response


        //      this.subscriptions.unsubscribe()
        // })

        this.observable = _shared.getTranslates()

        if(!! this.observable && !!this.observable[this.trnsl]) {
            renderer.setElementProperty(el.nativeElement, 'innerHTML', this.observable[this.trnsl]);
        } else {
            renderer.setElementProperty(el.nativeElement, 'innerHTML', this.trnsl);
        } 
    }
}