import { Component, OnInit, Output, EventEmitter, ViewEncapsulation, Input } from '@angular/core';
import { AuthService } from '../../../../services/auth.service';
import { Router } from '@angular/router';
import { environment } from '../../../../../environments/environment.dev';
@Component({
  selector: 'app-employee-assessment-card',
  templateUrl: './employee-assessment-card.component.html',
  styleUrls: ['./employee-assessment-card.component.scss']
})
export class EmployeeAssessmentCardComponent implements OnInit {
  imagelink: string;
  @Input() title: string;
  @Input() primaryrecord = [];
  @Input() technicalrecord = [];
  @Input() businessrecord = [];
  @Input() allskills: any;
  @Input() role: any;
  @Output() cardId = new EventEmitter();
  @Output() hideSlidingBtn = new EventEmitter();
  @Output() gotoEvents = new EventEmitter <object> ();
  @Output() gotoLPEvents = new EventEmitter <object> ();
  count: number;
  constructor(private router: Router) { }

  ngOnInit() {
    this.count = 0;
    if (this.title === 'Primary Assessment') {
      this.count = this.primaryrecord.length;
      if (this.primaryrecord.length > 0) {
        this.primaryrecord.map(obj => this.allskills.map(data => {
          if (obj.primary.length > 0) {
            if (obj.primary[0].pgSkillTrackMstr.skillTrackMstrId === data.skillTrackMstrId) {
              obj.skillTrackName = data.skillTrackName;
            }
          }
        }));
      }


      console.log(this.primaryrecord);
    }
    if (this.title === 'Technical Usecase Assessment') {
      if (this.technicalrecord.length > 0) {
        this.technicalrecord.map(obj => this.allskills.map(data => {
          if (obj.technical.length > 0) {
            if (obj.technical[0].skillTrackMstrId === data.skillTrackMstrId) {
              obj.skillTrackName = data.skillTrackName;
            }
          }
        }));
      }

      console.log(this.technicalrecord);
    }
    if (this.title === 'Business Usecase Assessment') {
      this.count = this.businessrecord.length;
      if (this.businessrecord.length > 0) {
        this.businessrecord.map(obj => this.allskills.map(data => {
          if (obj.business.length > 0) {
            if (obj.business[0].skillTrackMstrId === data.skillTrackMstrId) {
              obj.skillTrackName = data.skillTrackName;
            }
          }
        }));
      }
      console.log(this.businessrecord);

    }
    this.imagelink = environment.imageUrl+'/assets/img/employee/newdashboard/';
  }
  hideBtn() {
    this.hideSlidingBtn.emit(true);
  }
  getcolor(x, type) {
    const status = x.trim();
    let color = '';
    let img = '';
    switch (status) {
      // case 'Overdue':
      //   color = '#F97787';
      //   img = 'Overdue';
      //   return type === 'color' ? color : img;
      case 'OVERDUE' || 'Overdue':
        color = '#F97787';
        img = 'Overdue';
        return type === 'color' ? color : img;        
      case 'ASSIGNED':
        color = '#68CBFF';
        img = 'To Do';
        return type === 'color' ? color : img;
      case 'INPROGRESS':
        color = '#F8C580';
        img = 'InProgress';
        return type === 'color' ? color : img;
      case 'UNDER_REVIEW':
      case 'REVIEW_PENDING':
        color = '#9B9B9B';
        img = 'UnderReview';
        return type === 'color' ? color : img;
      case 'REVIEW_COMPLETED':
      case 'REVIEWING_COMPLETED':
        color = '#8BC2AC';
        img = 'Review Completed';
        return type === 'color' ? color : img;
      case 'DONE':
        color = '#15CC83';
        img = 'Done';
        return type === 'color' ? color : img;
      case 'TODO':
        color = '#68CBFF';
        img = 'To Do';
        return type === 'color' ? color : img;
    }
  }


  getcurrentstatus(x) {
    if (x === 'INPROGRESS') {
      return 'In Progress';
    } else if (x === 'REVIEW_COMPLETED' || x === 'REVIEWING_COMPLETED') {
      return 'Review Completed';
    } else if (x === 'ASSIGNED') {
      return 'To Do';
    } else if (x === 'UNDER_REVIEW' || x === 'REVIEW_PENDING') {
      return 'Under Review';
    } else if (x === 'DONE') {
      return 'Done';
    } else if (x === 'OVERDUE') {
      return 'Overdue';
    } else if (x === 'TODO') {
      return 'To Do';
    }

  }

  goToAssessment(assessmentId, eventId) {
    console.log(assessmentId, eventId);

    if (this.role === 'PGM') {
     this.gotoEvents.emit({assessmentId: assessmentId, eventId: eventId, title: this.title});
    }else {
      this.router.navigate(['employee/dashboard/employeeAssessment/', assessmentId, eventId]);

    }
  }

  showLearningCardDetails(data, id) {
    if (this.role === 'PGM') {
      this.gotoLPEvents.emit({title: this.title, learningPathId: id, assessmentStatus: data.userStatus });
    }else {
      this.router.navigate(['employee/dashboard/employeeLearningPath/', id]);
    }
  }
}
