import {Component, Input} from '@angular/core';
import {AuthenticationService} from "@app/_services";
import {Router} from "@angular/router";

@Component({
  selector: 'header-user-bar',
  templateUrl: 'header-user-bar.component.html',
  styleUrls: ['header-user-bar.component.scss']
})
export class HeaderUserBarComponent {
  @Input() user: any;
  public menuItems = <any>[];
  public ddHidden = false;

  constructor(public authService: AuthenticationService, private router: Router) {
  }

  get avatar() {
    return this.user?.avatar?.data;
  }
  get isJournalVisible() {
    return !this.authService.isMainCompanyMember || this.authService.isExpert || this.authService.isAdmin;
  }

  ngOnInit() {
    console.log(this.user)
  }


  close() {
    this.ddHidden = true;
    setTimeout(() => {this.ddHidden = false}, 10);
  }

  logout() {
    if (confirm('Вы деествительно хотите выйти из системы?')) {
      this.authService.logout();
      this.ddHidden = true;
      this.router.navigate(['']).then();
    }
  }

  link(link: string) {
    this.ddHidden = true;
    this.router.navigate([link]).then();
  }
}
