/**
 * Created by stefania on 3/21/16.
 */

import {Component, ElementRef, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {CommunityService} from '../../openaireLibrary/connect/community/community.service';
import {EnvProperties} from '../../openaireLibrary/utils/properties/env-properties';
import {HelperFunctions} from "../../openaireLibrary/utils/HelperFunctions.class";

@Component({
    selector: 'dashboard',
    templateUrl: 'dashboard.component.html',
})
export class DashboardComponent implements OnInit {
  communityId: string = null;
  communityType = null;
  properties: EnvProperties;

  constructor( private element: ElementRef,
               private  route: ActivatedRoute,
               private _communityService: CommunityService) {}

  ngOnInit() {
    this.route.data.subscribe((data: { envSpecific: EnvProperties }) => {
        this.properties = data.envSpecific;
        this.route.queryParams.subscribe(data => {
          HelperFunctions.scroll();
          this.communityId = ((data['communityId']) ? data['communityId'] : data['community']);
          this._communityService.getCommunity(this.properties, this.properties.communityAPI + this.communityId).subscribe (
            community => {
                this.communityType = community.type;
            },
            error => {
              console.error('Server responded: ' + error);
            }
          );
        });
    });

  }
}
