import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input} from "@angular/core";
import {HttpClient} from "@angular/common/http";
import {lastValueFrom} from "rxjs";

@Component({
    selector: "application-version",
    templateUrl: "./application_version.html",
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class ApplicationVersionComponent {
  private versionPrefix: string = $localize`:|ApplicationVersionComponent.versionPrefix:Версия:`;
  @Input()
  public applicationVersion: string;

  constructor(private httpClient: HttpClient, private cd: ChangeDetectorRef) {
    this.loadAppVersion(); //TODO: check version url
  }

  private loadAppVersion() {
    lastValueFrom(this.httpClient.get("version")).then((version: any) => {
      this.applicationVersion = this.versionPrefix + ' ' + version.number;
      this.cd.markForCheck();
    })
  }
}
