import { Validators } from '@angular/forms';
import { forEach } from '@angular/router/src/utils/collection';
import { map } from 'rxjs/operators/map';
import { SchedulePrimaryTestDataService } from './../../../coach/shared/service/schedule-primary-test-data.service';
import { Component, OnInit } from '@angular/core';
import { LocalStorageService } from 'angular-2-local-storage';
import { EmployeeHttpService } from 'app/services/employee/employee-http.service';
import {MatSnackBar, MdSnackBarConfig} from '@angular/material';
import { SuccessComponentComponent } from '../../shared/success-component/success-component.component';

@Component({
  selector: 'app-employee-new-dashboard',
  templateUrl: './employee-new-dashboard.component.html',
  styleUrls: ['./employee-new-dashboard.component.scss']
})
export class EmployeeNewDashboardComponent implements OnInit {
  day;
  monthIndex;
  year;
  projectTechStacks;
  projectDetailsInfo;
  projectDetailsInfoByUser;
  currentUser;
  isDetails;
  selectedViewPrj;
  constructor(private employeeService: EmployeeHttpService, public snackBar: MatSnackBar, protected localStorageService: LocalStorageService) {
  this.isDetails = false;
  }

  openSnackBar($event) {
    const extraClasses = ($event.type === 'success') ? ['successSnackBar'] : ['errorSnackBar'] ;
    const icon = ($event.type === 'success') ? 'done' : 'clear';
    this.snackBar.openFromComponent(SuccessComponentComponent, {
      duration: 1500,
      data: { message: $event.msg, type: $event.type, icon: icon},
      verticalPosition: 'top',
      extraClasses: extraClasses
    });
  }
  ngOnInit() {
    this.currentUser = this.localStorageService.get('userInfo');
    this.getAllProjects();
    this.getAllProjectsByUser();
    this.getAllTechStacks();
  }
  getAllTechStacks() {
    this.employeeService.getAllTechStacks().subscribe(resp => {
      this.projectTechStacks = resp;
       }, err => {
      console.log('Error on gett all TechStacks');
      });
  }
  getAllProjectsByUser() {
    this.employeeService.getAllProjectsByUser(this.currentUser.email).subscribe(resp => {
      this.projectDetailsInfoByUser = resp;
      }, err => {
      console.log('Error on gett all repo by user');
      });
  }
  getAllProjects() {
    this.employeeService.getAllProjects().subscribe(resp => {
      this.projectDetailsInfo = resp;
      }, err => {
      console.log('Error on gett all repo');
      });
  }

  getUpdatedResults() {
    this.getAllProjects();
    this.getAllProjectsByUser();
  }

 viewProjectDetails(event) {
  this.isDetails = event.val;
  this.selectedViewPrj = event.project;
 }
}
