import {Component} from '@angular/core';
import {Observable} from "rxjs";
import {PersonService} from "./person/person.service";
import {map} from "rxjs/operators";
import * as _ from 'underscore'
import {Router} from "@angular/router";
import {Title} from "@angular/platform-browser";

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

  public title = "FREIGELD"

  constructor(private titleService: Title, private personService: PersonService, private router: Router) {

  }

  hasAuth(): Observable<boolean> {
    return this.personService.getCurrentPerson().pipe(map(p => _.isObject(p.auth)))
  }

  logout() {
    this.personService.resetCurrentPerson()
    this.router.navigateByUrl("/")
  }

  setTitle(title: string) {
    this.titleService.setTitle(`${title} :: ${this.title}`);
  }
}
