import {Component} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {ConnectHelper} from "../../openaireLibrary/connect/connectHelper";
import {PiwikHelper} from "../../utils/piwikHelper";
import {Subscriber} from "rxjs";
import {properties} from "../../../environments/environment";


@Component({
    selector: 'openaire-my-claims',
    template: `
    <my-claims  [claimsInfoURL]=claimsInfoURL [userInfoURL]="userInfoURL" [communityId]=communityId [piwikSiteId]="piwikSiteId"></my-claims>
`

})
 export class OpenaireMyClaimsComponent {
  claimsInfoURL:string;
  userInfoURL: string;
  communityId:string;
  public piwikSiteId = null;

  constructor (private route: ActivatedRoute) {}
  sub;
  ngOnDestroy() {
    if (this.sub instanceof Subscriber) {
      this.sub.unsubscribe();
    }
  }
  public ngOnInit() {
      this.claimsInfoURL = properties.claimsInformationLink;
     this.userInfoURL = properties.userInfoUrl;
     this.sub = this.route.queryParams.subscribe(
       communityId => {
         this.communityId  = ConnectHelper.getCommunityFromDomain(properties.domain);
         if(!this.communityId) {
           this.communityId = communityId['communityId'];
         }
         this.piwikSiteId = PiwikHelper.getSiteId(this.communityId,properties.environment);
       });
        
  }

}
