import {Component, OnInit} from "@angular/core";
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
import {properties} from "../../environments/environment";

@Component({
  selector: 'users',
  templateUrl: 'users.component.html'
})
export class UsersComponent implements OnInit{
  
  public alias: string;
  public name: string;
  public type: string;
  public link: string;
  public loading: boolean;
  
  constructor(private stakeholderService: StakeholderService) {
  }
  
  ngOnInit() {
    this.loading = true;
    this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
      if(stakeholder) {
        this.alias = stakeholder.alias;
        this.name = stakeholder.name;
        this.type = stakeholder.type;
        this.link = this.getURL(this.alias);
        this.loading = false;
      }
    })
  }
  
  private getURL(id: string): string {
    return properties.domain + properties.baseLink + "/" + id + "?verify=";
  }
}
