import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { EventDetail } from 'app/models/candidate-dashboard-response/event-detail';
import { CandidateDashboardResponse } from 'app/models/candidate-dashboard-response/candidate-dashboard-response';
import { RoleNames } from 'app/models/auth/auth.model';
import { SetupWorkspacePayload } from 'app/models/sandbox-progress.model';
import { Assessment, PrimarySkills, TechnicalUsecase, UseCaseNames, AssessmentDetails } from 'app/models/assessment/assessment.model';
import { MatTabChangeEvent } from '@angular/material/material';
import { CandidateTechnicalSkillsComponent } from 'app/shared/candidate-details/candidate-technical-skills/candidate-technical-skills.component';
import { CandidateBusinessSkillsComponent } from 'app/shared/candidate-details/candidate-business-skills/candidate-business-skills.component';
import { Course } from 'app/models/capability-transformation/course-list.model';

@Component({
  selector: 'app-candidate-details-container',
  templateUrl: './candidate-details-container.component.html',
  styleUrls: ['./candidate-details-container.component.scss']
})
export class CandidateDetailsContainerComponent implements OnInit {
  @Input() tabSelectedIndex = 0;
  @Input() isAssessment : any;
  @Input() course: Course;
  @Output() selectedTabEvent = new EventEmitter<number>();

  _primarySkills: PrimarySkills;
  _assessmentDetails: AssessmentDetails;
  _employeeTechnicalUsecase: TechnicalUsecase;
  _candidateDashboard: CandidateDashboardResponse;
  _role: RoleNames;
  eventDetails: EventDetail[];

  eventDetailsPrimarySkill: EventDetail;
  eventDetailsTechnicalSkill: EventDetail;
  eventDetailsBusinessSkill: EventDetail;

  public roles = RoleNames;
  useCaseNames = UseCaseNames;

  @ViewChild(CandidateTechnicalSkillsComponent) techTabContent: CandidateTechnicalSkillsComponent;
  @ViewChild(CandidateBusinessSkillsComponent) businessTabContent: CandidateBusinessSkillsComponent;

  @Input('assessment')
  set assessment(assessment: Assessment) {
    this._primarySkills = Object.assign({}, assessment.primarySkills);
    this._assessmentDetails = Object.assign({}, assessment.assessmentDetails);
    this._employeeTechnicalUsecase = Object.assign({}, assessment.technicalUsecase);
  }

  @Input('candidate')
  set candidateDashboard(cd: CandidateDashboardResponse) {
    this._candidateDashboard = cd;
    if (cd !== undefined) {
      this.eventDetailsPrimarySkill = cd.eventDetails[0];
      this.eventDetailsTechnicalSkill = cd.eventDetails[1];
      this.eventDetailsBusinessSkill = cd.eventDetails[2];
    }

    this.setTabAccess();
  }

  get candidateDashboard() {
    return this._candidateDashboard;
  }

  get role() {
    return this._role;
  }

  @Input()
  set role(role) {
    this._role = role;
    this.setTabAccess();
  }


  constructor() {
  }

  ngOnInit() {
    if (!this.course) {
      this.course = new Course();
    }
  }

  private setTabAccess() {

  }

  selectedTab(tabIndex: number) {
    this.selectedTabEvent.emit(tabIndex);

    if (this.techTabContent) {
      this.techTabContent.closeUseCase();
    }

    if (this.businessTabContent) {
      this.businessTabContent.closeUseCase();
    }
  }

}
