import { Component } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { environment } from "../environments/environment";
import { buildInfo } from "../build";
import { AppService } from './services/app.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {

  title: string = "LEC";

  constructor(public translate: TranslateService, public app: AppService) {

    console.log(
        `\n%cBuild Info:\n\n` +
        `%c ❯ Environment: %c${environment.production ? "production 🏭" : "development 🚧"}\n` +
        `%c ❯ Build Version: ${buildInfo.version}\n` +
        ` ❯ Build Timestamp: ${buildInfo.timestamp}\n` +
        ` ❯ Author: %c${buildInfo.user || "<no message>"}\n`,
        "font-size: 14px; color: #7c7c7b;",
        "font-size: 12px; color: #7c7c7b",
        environment.production ? "font-size: 12px; color: #95c230;" : "font-size: 12px; color: #e26565;",
        "font-size: 12px; color: #7c7c7b",
        "font-size: 12px; color: #bdc6cf",
    );

    translate.addLangs(['it', 'en']);
    // this language will be used as a fallback when a translation isn't found in the current language
    translate.setDefaultLang('en');

    // the lang to use, if the lang isn't available, it will use the current loader to get them
    const browserLang = this.app.getLanguage() || translate.getBrowserLang() || 'en';
    app.setLanguage(translate, browserLang.match(/en|it/) ? browserLang : 'en');
  }

  ngOnInit() {
  }
}
