import {Component, Input, OnInit} from '@angular/core';
import {ApiService} from '../api.service';
import {AppComponent} from '../app.component';
import AppStorage from '../app.storage';

@Component({
  selector: 'app-topbar',
  templateUrl: './topbar.component.html',
  styleUrls: ['./topbar.component.scss']
})
export class TopbarComponent implements OnInit {
  @Input() token: string;

  constructor(private apiService: ApiService) {
  }

  ngOnInit(): void {
  }

  logout(): void {
    this.apiService.deleteAuthToken(AppStorage.getToken()).toPromise()
      .then()
      .catch(
        (error) => {console.log(error); }
      );

    AppStorage.setToken(null);
    AppComponent.token = null;
  }
}
