import {ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy} from "@angular/core";
import {AuthorizationService} from "../service/authorization.service";
import {Subscription} from "rxjs";

@Component({
  moduleId: module.id,
  selector: "app-header",
  templateUrl: "../../../../../src/resources/template/app/component/app_header.html",
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppHeaderComponent implements OnDestroy {

  name: string;
  realm: string;

  private subscription: Subscription;

  constructor(protected authService: AuthorizationService, protected cd: ChangeDetectorRef) {
    this.subscription = authService.onSessionUpdate
        .subscribe(session => {
          this.name = session.name;
          this.realm = session.realm;
          cd.markForCheck();
        })
  }

  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }
}
