import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { CandidateDashboardResponse } from 'app/models/candidate-dashboard-response/candidate-dashboard-response';
import { Email } from 'app/models/email';
import { CANDIDATE_STATUS, MAP_CANDIDATE_STATUS } from 'app/models/candidateStatus';
import { PrimarySkillsTimeline } from 'app/models/assessment/primary-skills-timeline';


@Component({
  selector: 'app-candidate-primary-skills-timeline',
  templateUrl: './candidate-primary-skills-timeline.component.html',
  styleUrls: ['./candidate-primary-skills-timeline.component.css']
})
export class CandidatePrimarySkillsTimelineComponent implements OnInit {

  private _candidateDashboard: CandidateDashboardResponse;

  private _primarySkillsTimeline: PrimarySkillsTimeline;

  @Input()
  email: Email;

  state: string;

  @Output()
  onViewDetailsClick = new EventEmitter<void>();

  @Input('primarySkillsTimeline')
  set primarySkillsTimeline(primarySkillsTimeline: PrimarySkillsTimeline) {
    this._primarySkillsTimeline = primarySkillsTimeline;

    const status = MAP_CANDIDATE_STATUS[this._primarySkillsTimeline.state];

    /* The score is available on primarySkillsTimeline.score */
    /* const score = parseInt(cd.eventDetails[0].eventScore, 10); */
    if (status === CANDIDATE_STATUS.METTL_REJECTED) {
      this.state = 'rejected';
    } else if (status === CANDIDATE_STATUS.METTL_REVIEW) {
      this.state = 'pending';
    } else if (status === CANDIDATE_STATUS.METTL_APPROVED || status >= CANDIDATE_STATUS.COACH_ASSIGNED) {
      this.state = 'accepted';
    } else {
      this.state = 'default';
    }
  }

  get primarySkillsTimeline() {
    return this._primarySkillsTimeline;
  }

  constructor() { }

  ngOnInit() {
  }

  viewReportClicked() {
    this.onViewDetailsClick.emit();
  }

}
