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

@Component({
  moduleId: module.id,
  selector: "application-version",
  templateUrl: "../../../../../src/resources/template/app/component/application_version.html",
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ApplicationVersionComponent {
  @Input()
  public applicationVersion: string;

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

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