import { Component, OnInit, Input } from '@angular/core';
import { AuthService } from '../services/auth.service';
import { LocalStorageService } from 'angular-2-local-storage';


import {Router} from '@angular/router';
import {NavigationService} from '../services/navigation/navigation.service';
import { NgModel } from '@angular/forms';
import {WorkspaceService} from '../services/workspace.service';
import { environment } from '../../environments/environment.dev'
@Component({
  selector: 'app-worskspace-launch',
  templateUrl: './worskspace-launch.component.html',
  styleUrls: ['./worskspace-launch.component.css']
})
export class WorskspaceLaunchComponent implements OnInit {

  sessionDetails: any;
  name: string;
  output: any;
  reqData: any;
  dashBoards: any[];
  candidate= {
    "id":"",
    "name":"",
    "email":"",
    "skills":"",
    "level":""
  };
  createdWorkspace:any;

  @Input() id: string='';
  imgUrl = environment.imageUrl;
  constructor(protected localStorageService: LocalStorageService,
              private AuthService:AuthService,
              private router: Router,
              private navigate:NavigationService,
              private WorkspaceService:WorkspaceService) { }


  ngOnInit() {
    var reqData = {};


    this.reqData = this.localStorageService.get('authToken');


    console.log(this.reqData['fullName']);


    this.name = this.reqData['fullName'];


    this.AuthService.dashBoardDetails(this.reqData).then(resp => {


      this.output = JSON.parse(resp);


      console.log(this.output);


      this.dashBoards = this.output.eventDetails;


      if (resp) {

      } else {

      }
    }).catch(err =>{
      console.log(err)

    });
    console.log(this.sessionDetails);
  }

  Candidates = [
    {
      "id":"0001",
      "name":"JohnDoe",
      "email":"johndoe@gmail.com",
      "skills":"java",
      "level":"3"
    },
    {
      "id":"0010",
      "name":"Bellamy Blake",
      "email":"blake@gmail.com",
      "skills":"java",
      "level":"3"
    },
    {
      "id":"0011",
      "name":"RosieLarsen",
      "email":"Rosie@gmail.com",
      "skills":"java",
      "level":"3"
    },
    {
      "id":"0100",
      "name":"SarahLinden",
      "email":"Linden@gmail.com",
      "skills":"java",
      "level":"3"
    },
    {
      "id":"0101",
      "name":"StephenHolder",
      "email":"Holder@gmail.com",
      "skills":"java",
      "level":"3"
    },
    {
      "id":"0110",
      "name":"JamesSkinner",
      "email":"Skinner@gmail.com",
      "skills":"java",
      "level":"3"
    }

  ];

  goToDashboard(){
    this.router.navigate(['dashboard']);
  }


  searchCandidate(){

    console.log(event);
    for (var i=0;i< this.Candidates.length; i++){
      if(this.id == this.Candidates[i].id){

        this.candidate = this.Candidates[i];
      }

    }
  }

  createWorkspace(val){
    this.WorkspaceService.createWorkspace({user: val}).then(resp => {

      console.log("createWorkspace");
      console.log("resp:"+resp);
      this.createdWorkspace = resp;

      //sets the workspaceId
      this.WorkspaceService.setWorkspaceId(val, this.createdWorkspace);

    /*  if (resp.State == 'AVAILABLE') {
        this.WorkspaceService.startWorkspace(resp.WorkspaceId );
      } else {

      }*/
    }).catch(err =>{
      console.log(err)

    });

  }


}
