import { Component, inject } from '@angular/core'; import { CommonModule } from '@angular/common'; import { MatIconModule } from '@angular/material/icon'; import { Router, RouterLink, RouterOutlet } from '@angular/router'; import { HttpClient } from '@angular/common/http'; import { AuthService } from 'src/app/_helpers/services/auth.service'; @Component({ selector: 'bgui-navbar', standalone: true, imports: [CommonModule, MatIconModule], providers: [AuthService, RouterLink, RouterOutlet], templateUrl: './navbar.component.html', styleUrls: ['./navbar.component.scss'], }) export class NavbarComponent { userEmail: string | null | undefined; private clockInterval: any; public date = new Date(); private router = inject(Router); constructor(private http: HttpClient) {} ngOnInit() { this.userEmail = localStorage.getItem('username'); console.log(this.userEmail); this.startClock(); } deconnxionlogin() { localStorage.setItem('isLoggedIn', 'false'); localStorage.removeItem('token'); sessionStorage.removeItem('username'); // // Remplacez 'page-accueil' par l'URL de la page à laquelle vous souhaitez rediriger // console.log("Redirection vers 'dash'"); this.router.navigate(['/auth']); // //window.location.href = '/'; } ngOnDestroy() { if (this.clockInterval) { clearInterval(this.clockInterval); } } private startClock() { this.updateClock(); // Initial call to display clock immediately this.clockInterval = setInterval(() => this.updateClock(), 1000); } private updateClock() { const now = new Date(); const hours = String(now.getHours()).padStart(2, '0'); const minutes = String(now.getMinutes()).padStart(2, '0'); const seconds = String(now.getSeconds()).padStart(2, '0'); const timeString = `${hours}:${minutes}:${seconds}`; const clockElement = document.getElementById('clock'); if (clockElement) { clockElement.textContent = timeString; } } }