import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Role } from '@msfa-models/role.model';
import { UserService } from '@msfa-services/api/user.service';
import { Observable } from 'rxjs';
import { filter, map } from 'rxjs/operators';

@Component({
  selector: 'msfa-start',
  templateUrl: './start.component.html',
  styleUrls: ['./start.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StartComponent {
  userFullName$: Observable<string> = this.userService.user$.pipe(
    filter(user => !!user),
    map(userName => userName.fullName)
  );
  userRoles$: Observable<Role[]> = this.userService.userRoles$;

  constructor(private userService: UserService) {}

  isAuthorizedUser(userRoles: Role[]): boolean {
    return !!userRoles.length;
  }
}
