import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { LocalStorageService } from 'angular-2-local-storage';
import { NavBarService } from './coach.service';
import { environment } from '../../environments/environment.dev';

const coachPages = [
  { title: '', back: 'menu' },
  { title: 'Candidate Details', back: 'arrow_back' },
  { title: 'Employee Details', back: 'arrow_back' },
];

@Component({
  selector: 'app-coach',
  templateUrl: './coach.component.html',
  styleUrls: ['./coach.component.css'],
  providers: [NavBarService]
})
export class CoachComponent implements OnInit {

  currentPageNumber: number;
  roleStatus: boolean;
  selectedRole;
  currentPageData: { title: string, back: string};
  backLink = '/coach/landing/candidate';
  empData: {
    accessToken: any,
    loginType: any,
    fullName: any,
    firstName: any,
    userInfoMstrId: any,
    roleName: any,
    roles: any,
    skills: any,
    location: any
  };
  initials = '';
  onlyOneRole: boolean;
  frmCandD:boolean = false;
  imageUrl:string = environment.imageUrl;

  constructor(protected localStorageService: LocalStorageService,private navBarService: NavBarService, private router: Router) {
    this.selectedRole = this.localStorageService.get('selectedRole');
    if (window.location.origin !== 'http://localhost:8080') {
      var empData;
      empData = this.localStorageService.get('userInfo');
      this.empData = empData;
      if (empData['roles'].length > 1) {
        this.onlyOneRole = false;
      } else {
        this.onlyOneRole = true;
      }
      console.log(this.empData,"userInfo Detailssssss")
      if (this.empData['fullName']) {
        this.initials = this.empData['fullName'].replace(/\W*(\w)\w*/g, '$1').toUpperCase();
      }
    } else {
      this.initials = 'LS';
    }
    console.log('initials: ' + this.initials);
    navBarService.currentPage.subscribe((val: number) => {
      this.currentPageNumber = val;
      this.currentPageData = coachPages[this.currentPageNumber];
      if (this.currentPageNumber === 1) {
        this.backLink = '/coach/landing';
      }
      else if(this.currentPageNumber === 2){
        this.backLink = '/coach/landing/employee';
      }
      else {
        this.backLink = '/coach/landing';
      }
      console.log('getting page in parent: ' + val);
    });

  }

  ngOnInit() {
  }
  navigateBack() {
    this.router.navigate([this.backLink]);
  }
  // changeRole(){
  //   this.roleStatus = !this.roleStatus;
  // }
  changeRole(status){
    this.roleStatus = status;
  }  
  closeNavDetails(event){
    this.roleStatus = event;
  }  
  gotoLogout(evnt){

    console.log('logout');
    localStorage.clear();
    this.router.navigate([''])
  }

  openFeedModal(e){
    console.log(e);
    if(e == true){
      this.frmCandD = e
    }
  }

  closeFdModal(e){
    if(e == false){
      this.frmCandD = e;
    }
  }
}
