import { Component, PLATFORM_ID, Inject, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { User } from '@prisma/client';

import { UserService } from './user/user.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  public user?: User;

  constructor(
    @Inject(PLATFORM_ID) private readonly $platformId: any,
    private readonly $router: Router,
    private readonly $userService: UserService
  ) {}

  public ngOnInit() {
    this.$userService.user().subscribe((user) => (this.user = user));
  }

  public logout() {
    this.$userService.logout();
    this.$router.navigateByUrl('/');
  }

  public fullName(user: User) {
    return `${user.firstName} ${user.lastName}`;
  }
}
