import { Component, OnInit, Input, ViewEncapsulation } from '@angular/core';
import { EmployeeHttpService } from 'app/services/employee/employee-http.service';
import { Subject } from 'rxjs/Subject';
import { Router } from '@angular/router';
import { environment } from '../../../../environments/environment.dev';

@Component({
  selector: 'app-employee-review-list',
  templateUrl: './employee-review-list.component.html',
  styleUrls: ['./employee-review-list.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class EmployeeReviewListComponent implements OnInit {

  @Input() data: any[];
  @Input() reviewerId;
  private imagelink;
  private image;
  private $destroyed = new Subject();
  colors = ['#d831d8', '#138D75', '#2962ff', '#ef4d34', '#8B008B', '#1ea1e8', '#ffa500', '#ED4289', '#1EC7F9'];
  rows = [];
  columns = [
    { name: 'Name', prop: 'name' },
    { name: 'Id', prop: 'id' },
    { name: 'Assessment Type', prop: 'assessmentType' },
    { name: 'Experience Level', prop: 'experienceLevel' },
    { name: 'Assessment Name', prop: 'assessmentName' },
    { name: 'Status', prop: 'status' }
  ];

  columnWidths = [
    { column: 'name', width: 100 },
    { column: 'id', width: 30 },
    { column: 'assessmentType', width: 100 },
    { column: 'experienceLevel', width: 50 },
    { column: 'assessmentName', width: 150 },
    { column: 'status', width: 30 }
  ];


  constructor(private employeeHttpService: EmployeeHttpService,
    private router: Router) { }

  ngOnInit() {
    this.imagelink = environment.imageUrl+'/assets/img/employee/newdashboard/';
    // this.image = this.imagelink + 'user.PNG';
    this.rows = this.data;
  }

  getClassByValue(value: string) {
    switch (value) {
      case 'Overdue': return 'overdue-circle';
      case 'To Do': return 'todo-circle';
      case 'Done': return 'done-circle';
    }
  }

  getStatus(type) {
    const status = {
      'PENDING': 'To Do',
      'PASSED': 'Done',
      'REJECTED': 'Done',
      'DONE': 'Done',
      'default': 'Invalid'
    };
    return status[type] || status['default'];
  }

  getImageDetails(empId: string) {
    this.image = '';
    // this.employeeHttpService.getEmployeeImage(empId)
    //   .subscribe(data => {
    //     if (data[0].fileContent !== "" || data[0].fileContent !== undefined) {
    //       this.image = 'data:image/jpg;base64,' + data[0].fileContent;
    //     }
    //   });
    return this.image;
  }


  getInitials(fullName: string) {
    if (fullName) {
      return fullName.replace(/\W*(\w)\w*/g, '$1').toUpperCase();
    }
  }

  navigate(adId: string) {
    this.router.navigate(['/employee/dashboard/list', this.reviewerId, adId]);
  }

  randomColor(){
    return  this.colors[Math.floor(Math.random() * (this.colors.length-1)) + 0];
  }

}





