import { Component } from '@angular/core';
import { AuthService } from '../../../../cores/services/auth.service';
import { Router, RouterModule } from '@angular/router';
import { ToastrService } from 'ngx-toastr';


@Component({
  selector: 'app-sidebar',
  standalone: true,
  imports: [RouterModule],
  templateUrl: './sidebar.component.html',
  styleUrls: ['./sidebar.component.scss']
})
export class SidebarComponent {
  fullName: string | null = null;
  avatar: string | null = null;

  constructor(private authService: AuthService, private router: Router, private toast: ToastrService) {
    this.fullName = this.authService.getUserFullName(); 
    this.avatar = this.authService.getAvatar(); 
  }

  onLogout(): void {
    this.authService.logout().subscribe(
      () => {
        this.router.navigate(['/auth']); 
        this.toast.success('Logout successful');
      },
      (error: any) => {
        this.toast.error(error.error.message);
      }
    );
  }
}
