import { Component, OnInit, Input } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AdmindataService} from '../shared/admindata.service';
import { DataFinder } from '../shared/datafinder'
import { Injectable }     from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { AuthService } from '../../services/auth.service';
import { environment } from '../../../environments/environment.dev';

@Component({
  selector: 'app-nlanding-page',
  templateUrl: './nlanding-page.component.html',
  styleUrls: ['./nlanding-page.component.scss']
})

@Injectable()

export class NlandingPageComponent implements OnInit {

  adminBs: any;
  adminConf: any;
  adminEmp: any;
  adminCand: any;
  adminUmgmt: any;
  @Input() aldata: any;
  userCounts: any;

  adminImg_path = environment.imageUrl+'/assets/img/admin/';
  constructor(private route: ActivatedRoute, private router: Router, private _data: AdmindataService, private http: Http, private AuthService: AuthService, private dataFinder : DataFinder) {
    this.getAllUsers();

}

  ngOnInit() {
    this.dataFinder.getJSONDataAsync("../../../assets/data/adminlanding.json").then(data => {
      this.SetQueryOptionsData(data);
    });
  }
/* Sets data with returned JSON array */
SetQueryOptionsData(data: any) {
  this.adminBs = data.adminBs;
  this.adminConf = data.adminConf;
  this.adminEmp = data.adminEmp;
  this.adminCand = data.adminCand;
  this.adminUmgmt = data.adminUmgmt;
}
  
gotoInnerPage(id,myarray){    
  this.aldata = myarray;
  this._data.updatedArray(this.aldata);
  if(id.id == 1 || id.id == 2 || id.id == 4 || id.id == 5 ||  id.id == 6 ||  id.id == 7 ||  id.id == 9 || id.id == 11 || id.id == 13 || id.id == 14 || id.id == 15){
    //   id.id== 9 || id.id == 8 ||
    this.router.navigate(['admin/inner-page/'+id.id]);
  }
  else{
    console.log(id);
    console.log(myarray);
    this.router.navigate(['admin/'+id.link]);
    }
  }

  getAllUsers(){
    this.AuthService.getAllUserCount().then(resp => {
      const theUsers = JSON.parse(resp);
      this.userCounts = theUsers;
     
    }).catch(err =>{
      console.log(err)
    })
  }
}
