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-linking-generic',
    template: `<linking-generic [communityId]=communityId [piwikSiteId]="piwikSiteId" pageTitle="Linking"></linking-generic>`

})
export class OpenaireLinkingComponent {
  communityId:string;
  public piwikSiteId = null;
  sub;
  ngOnDestroy() {
    if (this.sub instanceof Subscriber) {
      this.sub.unsubscribe();
    }
  }
  constructor (private route: ActivatedRoute) {
      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);
        });
  }
}
