import { Component } from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
import { SubjectService } from './providers/subject.service';
import { WebService } from './providers/web.service';
import * as $ from 'jquery';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'forex';
  lang =  'en';
  constructor(translate: TranslateService, public subjectService: SubjectService, public service: WebService){

    this.subjectService.getLangData().subscribe(langData => {
      console.log(langData);
      this.lang = this.service.getLocalStorageItem('lang');
      console.log(this.lang);
      if (this.lang) {
        translate.setDefaultLang(this.lang);
        translate.use(this.lang);
      }
    });


    const lang  = this.service.getLocalStorageItem('lang');
    console.log(lang);

    if(lang !== undefined){
      this.lang = lang;
    }

    if(this.lang === 'ar') {
      $('body').addClass('ar');
    } else {
      $('body').removeClass('ar');
    }

    this.lang = 'en';

    translate.setDefaultLang(this.lang);

    // the lang to use, if the lang isn't available, it will use the current loader to get them

    translate.use(this.lang);

    // the lang to use, if the lang isn't available, it will use the current loader to get them


  }
}
