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

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit {
  menuConfig = {
    closeOnCLick: true
  };
  selectedRole;
  @Input() getColor: string;
  @Input() changeColor: string;
  @Input() adminAvatarColor: string;
  @Input() getAvatarName: string;
  @Input() getcurrentPageNumber: number;
  @Input() getBackLink: string;
  @Input() changeNavIcon: boolean;
  @Input() onboardTab: boolean;
  @Input() getcurrentPageData: any;
  @Input() backWithoutRouting: boolean;
  @Input() menuListItem: Array<object>;
  @Output() getchangedRole = new EventEmitter();
  @Output() openHeaderMenu = new EventEmitter();
  @Output() navigateBackToPrev = new EventEmitter();
  @Output() closeHeaderMenu = new EventEmitter();
  @Output() itemSelectedInMenu = new EventEmitter();
  @Input() roleStatus = false;
  @Input() disableUserInfoNav: boolean;
  @Output() backNavClicked = new EventEmitter();
  intFbModal: boolean;
  img_path: string;
  @Output() initFeedbackModal = new EventEmitter();
  
  constructor(private router: Router, protected localStorageService: LocalStorageService, ) {
    // private navBarService: NavBarService,
    this.selectedRole = this.localStorageService.get('selectedRole');
    console.log(this.getcurrentPageNumber);
    console.log(this.getcurrentPageData);
    this.img_path = environment.imageUrl+'/assets/img/candidate/dashboard/';
    this.intFbModal = false;
  }

  ngOnInit() {
    console.log(this.getBackLink);
  }
  changeRole() {
    this.roleStatus = !this.roleStatus;
    this.getchangedRole.emit(this.roleStatus)
  }
  disableUserInfo() {
    return this.disableUserInfoNav;
  }
  navigateBackWithoutRouting() {
    this.navigateBackToPrev.emit();
  }
  navigateBack() {
    this.router.navigate([this.getBackLink]);
    this.backNavClicked.emit(true);
    console.log(this.getcurrentPageNumber);
    console.log(this.getcurrentPageData);
    console.log(this.getBackLink);
    this.onClose()

    if(this.getcurrentPageData.title == "Welcome to Admin"){

      this.router.navigate(['employee']);

    }
    if(this.getcurrentPageData.title == 'List of Profiles'){

      this.router.navigate(['employee']);

    }

    if (this.getBackLink == '/ta') {
      this.getcurrentPageNumber = 0;
      this.getcurrentPageData = { title: 'List of Profiles', back: 'menu' };
      // this.navBarService.setCurrentPage(0);
    }
    else {
      console.log(this.getBackLink,"header component - other service call");
      // this.navBarService.setCurrentPage(0);
      // this.getcurrentPageData= {title: 'Welcome to Admin', back: 'menu' };
    }
  }
  onOpen() {
    this.openHeaderMenu.emit();
  }
  onClose() {
    this.closeHeaderMenu.emit();
  }
  onItemSelected(event) {
    this.itemSelectedInMenu.emit(event);
  }
  feedModal(status){
    this.intFbModal = status
    this.initFeedbackModal.emit(this.intFbModal);
  }
}
