import { Component, inject, ChangeDetectorRef } from '@angular/core';
import { NgbCollapseModule } from '@ng-bootstrap/ng-bootstrap';
import { userDropdownItems } from '@layouts/components/data';
import { AuthService } from '@/app/core/services/auth.service';

@Component({
  selector: 'app-user-profile',
  standalone: true,
  imports: [NgbCollapseModule],
  templateUrl: './user-profile.component.html',
})
export class UserProfileComponent {
  private authService = inject(AuthService);
  private cdr = inject(ChangeDetectorRef);

  user: any = null;

  constructor() {
    this.loadUser();
    this.authService.onAuthState().subscribe(() => this.loadUser());
  }

  loadUser() {
    this.authService.getProfile().subscribe({
      next: profile => {
        this.user = profile;     
        this.cdr.detectChanges();
      },
      error: () => {
        this.user = null;
        this.cdr.detectChanges();
      }
    });
  }
}
