import { Component, OnInit, Input } from '@angular/core';
import { NavBarService } from '../../../admin.service';
import { AuthService } from '../../../../services/auth.service';
import _ from "lodash";
import { environment } from '../../../../../environments/environment.dev';

@Component({
  selector: 'app-skilset-admin',
  templateUrl: './skilset-admin.component.html',
  styleUrls: ['./skilset-admin.component.scss']
})
export class SkilsetAdminComponent implements OnInit {

  img_path = environment.imageUrl+'/assets/img/Taflow/';
  skills: any;
  skilltrackResponse: any;
  skillsetForm: boolean = false;
  addNewSsForm: boolean;
  skFormTitle: string;

  constructor(private AuthService: AuthService) {
    this.getAllSkills();
   }

  ngOnInit() {
  }


  getAllSkills(){

    this.AuthService.getAllSkill().then(resp =>{
      console.log(resp,'getAllSkill')
      this.skills = resp.pgSkillTrackDtlsList
      var customSkill = []
      var skills = _.uniqBy(resp.pgSkillTrackDtlsList,'pgSkillTrackMstr.skillTrackName')
      var masterSkills = _.uniqBy(_.flattenDeep(skills.map(i => i.pgSkillTrackMstr)))
      masterSkills.forEach(usrSkills => {
        var dtlsSkill = resp.pgSkillTrackDtlsList.filter(item => item.pgSkillTrackMstr.skillTrackName == usrSkills.skillTrackName)
        var skillTrackDtlsName = _.uniqBy(_.flattenDeep(dtlsSkill.filter(i => {return {id : i.skillTrackDtlsId, name : i.skillTrackDtlsName}})))
        customSkill.push({skillMaster:usrSkills,skillTrackDtls :dtlsSkill,skillTrackDtlsName:skillTrackDtlsName});
      });
      console.log(customSkill);
      this.skilltrackResponse = customSkill;
    }).catch(err =>{

      console.log(err)
    })
  }

  addNewSkillset(){
    this.skillsetForm = true;
    this.addNewSsForm = true;
    this.skFormTitle = "Add SkillSet"
  }

  editExstingSkillset(e){
    console.log(JSON.stringify(e));
  }

  skillFormCancelled(e){
    this.skillsetForm = false;
  }
}
