import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

@Component({
  selector: 'app-journal-settings',
  templateUrl: './journal-settings.component.html',
  styleUrl: './journal-settings.component.scss',
})
export class JournalSettingsComponent {
  language = '1';
  constructor(private translate: TranslateService) {}

  ngAfterViewInit() {
    let lang = this.translate.getDefaultLang();
    if (lang === 'en') {
      this.language = '2';
    } else {
      this.language = '1';
    }
  }

  public setLanguage(lang: string): void {
    this.translate.setDefaultLang(lang);
    this.translate.use(lang);
    localStorage.setItem('language', lang);
    console.log('Language set to: ', lang);
  }
}
