import { Component, OnInit, Input,Output, EventEmitter } from '@angular/core';
import _ from "lodash";
import { environment } from '../../../../environments/environment.dev';

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


  @Input() coach:any;
  @Input() status:string;
  @Input() approval:string;
  @Output() coachID = new EventEmitter<string>();
  @Output() scheduleId = new EventEmitter<string>();
  @Output() approve = new EventEmitter<object>();
  @Output() reject = new EventEmitter<object>();

  isRow= true;
  imageUrl: string = environment.imageUrl;
  constructor() { }

  ngOnInit() {
    console.log(this.approval);
    if(!this.approval){
      this.approval = 'hide';
    }
  }

  Initials(cString) {

    if(cString) {
      return cString.replace(/\W*(\w)\w*/g, '$1').toUpperCase()
    }
  }


  skillMstrs(userData) {
    let masterSkillId = []
    let masterSkills = []
    masterSkills = _.uniqBy(userData.userInfoMstr.pgUserSkillMapping, 'pgSkillTrackDtls.pgSkillTrackMstr.description');


    masterSkills.forEach(usrSkills => {
      masterSkillId.push(usrSkills.pgSkillTrackDtls.pgSkillTrackMstr.description);
    });
    return masterSkillId;
  }

  Selected(ID) {
    this.coachID.emit(ID);
  }

  schedule(ID){
    this.scheduleId.emit(ID);
  }

  Approve(decision, status){
    console.log("status,status ",status);
    if( status == "METTL_REVIEW" && decision == "show"){
      console.log('METTL_REVIEW',decision);
      this.approval = decision;
    }
    else if (decision == 'hide'){
      this.approval = decision;
      console.log('METTL_REVIEW no hide');
    }


  }
  confirmApprove(id,status){

    this.approve.emit({userId:id, status:status});
    console.log("confirm approve");
  }
  confirmReject(id,status){
    this.reject.emit({userId:id, status:status});
  }
  over(){
    this.isRow= false;
  }

  onUnovering(){

    this.isRow= true;
  }
}
