import { Component, Renderer2 } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../../auth/services/auth.service';
import { AuthPasajerosService } from '../../auth/services/auth-pasajeros.service';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css']
})
export class HeaderComponent {

  constructor(
    private router: Router, private renderer: Renderer2, private authService: AuthService,private authPasajeroSerice: AuthPasajerosService
  ){}

  get auth(){
    return localStorage.getItem('usuario') || localStorage.getItem('correo');
  }

  logOut(){
    if (localStorage.getItem('usuario')) {
      this.authService.logout();
      this.router.navigate(['/auth/login']);
    } else if (localStorage.getItem('correo')){
      this.authPasajeroSerice.logout();
      this.router.navigate(['/auth/login-pasajero']);
    }
  }

  cambiarVistaSidebar(){
    var sidebar = document.getElementById('sidebar-nav');
    if (!document.body.classList.contains('mini-navbar')) {
      this.renderer.addClass(document.body, 'mini-navbar');
      sidebar!.classList.remove('animated')
      sidebar!.classList.remove('fadeIn');
    } else {
      sidebar!.classList.add('animated');
      sidebar!.classList.add('fadeIn');
      this.renderer.removeClass(document.body,'mini-navbar');
    }
  }

}
