import {Component, Inject, PLATFORM_ID} from '@angular/core';
import {isPlatformBrowser} from "@angular/common";
import {AppState} from "./modules/shared/app-state";
import {Observable} from "rxjs";
import {SubscribingComponent} from "./modules/shared/components/subscribing.component";

@Component({
  selector: 'cre-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.sass']
})
export class AppComponent extends SubscribingComponent {
  isOnline: boolean
  isServerOnline = true

  constructor(
    @Inject(PLATFORM_ID) private platformId: object,
    private appState: AppState
  ) {
    super()
  }

  ngOnInit() {
    this.isOnline = isPlatformBrowser(this.platformId)
    super.ngOnInit();

    this.subscribe(
      this.appState.serverOnline$,
      {
        next: online => this.isServerOnline = online
      }
    )
  }

  reload() {
    window.location.reload()
  }
}
