
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../../../../services/auth.service';
import _ from "lodash";
import { HostListener } from '@angular/core';
import { LocalStorageService } from 'angular-2-local-storage';
import { EmployeeHttpService } from 'app/services/employee/employee-http.service';
import { UsecaselistService } from '../usecase-list/usecaselist.service';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
import { PagerService } from '../user-mgmt/_services/index';
import { environment } from '../../../../../environments/environment.dev';

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

  img_path = environment.imageUrl+'/assets/img/admin/';
  lp_img_path = environment.imageUrl+'/assets/img/Taflow/';
  ep_imgPath = environment.imageUrl+'/assets/img/employee/shared/';
  ep2_imgPath = environment.imageUrl+'/assets/img/employee/';
  tilesDisplay: boolean = true;
  isDesc: boolean = false;
  column: string = 'lpname';
  records: Array<any>;
  showFilter: boolean = false;
  newLearningPath: boolean = false;
  skFormTitle: string;
  skillCategory: any;
  skilltrackResponse: any;
  skills: any;
  selectedMskillsArr: any = [];
  learningPathList: any;
  learningPathListCopy:any;
  // otherIconsLpTable: boolean = false;
  rowIndex: number;
  key: any;
  keyClearMethod: boolean;
  newLpStep1: boolean = true;
  newLpStep2: boolean = false;
  newLpStep3: boolean = false;
  getIds: string;
  loader = true;
  coursesLists;
  allCourses;
  primaryAssessment;
  technicalAssessment;
  businessAssessment;
  allReservedCourses;
  primaryReservedAssessment;
  technicalReservedAssessment;
  businessReservedAssessment;
  skillMstrIds
  selectedSkill:any = [];
  tabDetails = [
    { className: 'first', Id: 2, containerText: 'Courses', count: 0 },
    { className: 'second', Id: 3, containerText: 'Primary Assessment', count: 0 },
    { className: 'third', Id: 4, containerText: 'Technical Assessment', count: 0 },
    { className: 'fourth', Id: 1, containerText: 'Business Assessment', count: 0 },
  ];
  allSelectedCourses: any = [];
  primarySelectedAssessment: any = [];
  technicalSelectedAssessment: any = [];
  businessSelectedAssessment: any = [];
  selectedCoursesDetails: any = [];
  selectedCourses: any = [];
  selectedCourseIdCollection: string;
  showcatdispDiv: boolean = false;
  selectedTab: number;
  documentDetails;
  tfrIds: any;
  expLevel: Explevel [];
  isLpUpdate: boolean = false;
  newLpReqs: any = {};
  reqData: any;
  successLpPage: boolean = false;
  lpConfData: any;
  learningPathId: number;
  theSelectedLearningPath: any;
  lpEntryStatus: string;
  editLpSkillTrackMstrIds: any = [];
  userInfoMstrId: number;
  dialogData: any;
  editLpbusinessAssIds: any;
  editLpcourseIds : any;
  editLpprimaryAssIds: any;
  editLptechnicalAssIds: any;
  editLpObjCount: number;
  steptwoNxtbtn: string;
  viewDetLpInfo: boolean = false;
  viewLpDetData: any;
  public returnedLPs;
  public fLevels : any = [];
  public fSkills = [];
  errMsg: any;
  theResp: any;
  usr_img_path = environment.imageUrl+'/assets/img/admin/';
    // pager object
    pager: any = {};
    // paged items
    pagedItems: any[];

  constructor(private AuthService: AuthService, protected localStorageService: LocalStorageService, private employeeHttpService: EmployeeHttpService,private usecaselistservice: UsecaselistService, private toastr: ToastsManager, private pagerService: PagerService) {
    this.getAllSkillsForLp();
    this.getAllLearningPath();
    this.documentDetails = document;
    this.selectedTab = 0;

    this.reqData = this.localStorageService.get('userInfo');
  }

  ngOnInit() {
    this.usecaselistservice.getExpLevel().subscribe((explevels) => {
      this.expLevel = explevels.pgExperienceList;
    });
    this.dialogData = { title: 'Learning Path Confirmation', text: 'Would you like to delete this Learning Path from the list?' };
  }
  toggleActive(newValue: number) {
    this.selectedTab = newValue;
  }

  toggleLpListView(){
    this.tilesDisplay = false;
  }

  toggleLpGridView(){
    this.tilesDisplay = true;
  }

  sort(property){
    this.isDesc = !this.isDesc; //change the direction
    this.column = property;
    let direction = this.isDesc ? 1 : -1;

    this.records.sort(function(a, b){
        if(a[property] < b[property]){
            return -1 * direction;
        }
        else if( a[property] > b[property]){
            return 1 * direction;
        }
        else{
            return 0;
        }
    });
  };

  showLpFilter(){
    if(this.learningPathList.length == 0){
      this.getAllLearningPath();
    }
    this.showFilter = true;
  }
  closeFilter(){
    this.showFilter = false;
  }

  addLearningPath(){
    this.newLearningPath = true;
    this.successLpPage = false;
    this.newLpStep1 = true;
    this.skFormTitle = 'Create New Learning Path';
    if(this.selectedMskillsArr.length > 0){
      this.selectedMskillsArr.splice(0);
        this.skilltrackResponse.forEach(element => {
          element.isSelected = false;
        });
    }
    if(this.allSelectedCourses.length > 0){
      this.allSelectedCourses.splice(0);
      this.allSelectedCourses.forEach(element =>{
        element.isSelected = false;
      })
    }
    if(this.primarySelectedAssessment.length > 0){
      this.primarySelectedAssessment.splice(0);
      this.primarySelectedAssessment.forEach(element =>{
        element.isSelected = false;
      })
    }
    if(this.businessSelectedAssessment.length > 0){
      this.businessSelectedAssessment.splice(0);
      this.businessSelectedAssessment.forEach(element =>{
        element.isSelected = false;
      })
    }
  }

  gotoPrevpage(){
    this.newLearningPath = false;
    this.viewDetLpInfo = false;
    this.skFormTitle = '';
  }

  getAllSkillsForLp(){

    this.AuthService.getAllSkillTrackMstrAndDtls().then(resp =>{
      this.skilltrackResponse = resp;
    }).catch(err =>{
      console.log(err)
    })
  }

  getAllLearningPath(){
    this.AuthService.getAllLearningPaths().then(resp => {
      this.learningPathList = resp.learningPathList;
      this.learningPathListCopy = resp.learningPathList;
      console.log(this.learningPathList);
      this.setPage(1);
      this.returnedLPs = this.learningPathList;
      // this.fLevels = _.uniqBy(this.returnedLPs, 'pgExperienceLevelId')
      // this.fSkills = _.uniqBy(this.returnedLPs, 'infoDetails.jobId')

      let YY = _.uniq(_.flattenDeep(this.returnedLPs.map(i =>
        i.skillNames.map(j => j)
      )));

      YY.forEach(i => {
        this.fSkills.push({name:i,checked:false});
      });

      let XX = _.uniq(_.flattenDeep(this.returnedLPs.map(i =>
        i.pgExperienceLevelName
      )));

      XX.forEach(i => {
        this.fLevels.push({name:i,checked:false});
      })
    });
  }

  setPage(page: number) {
    if(this.pager.totalPages){
      if (page < 1 || page > this.pager.totalPages) {
          return;
      }
    }
    // get pager object from service
    this.pager = this.pagerService.getPager(this.learningPathList.length, page);
    // get current page of items
    this.pagedItems = this.learningPathList.slice(this.pager.startIndex, this.pager.endIndex + 1);
    // this.learningPathListCopy = this.pagedItems;
  }

  addSelectedSkills(e){
    if (this.selectedMskillsArr.indexOf(e) !== -1) {
      console.log("Item already exists");
    }
    else {
      this.selectedMskillsArr.push(e);
      console.log(this.selectedMskillsArr);
    }
  }

  showOtherIconsTable(index){
    this.rowIndex = index;
    console.log(this.rowIndex);
  }

  @HostListener('document:keyup', ['$event'])
  handleKeyboardEvent(event: KeyboardEvent) {
    this.key = event.key;
    if(this.key == 'Escape'){
        // this.selectedMskillsArr = [];
        this.keyClearMethod = true;
        this.selectedMskillsArr.splice(0);
        this.skilltrackResponse.forEach(element => {
          element.isSelected = false;
        });
    }
  }

  deleteTabLearningPath(lpDdata,index){
    console.log(lpDdata);
    console.log("Index", index);
    this.deleteExistingLp(lpDdata);
  }
  editTabLearningPath(lpEdata,index){
    console.log(lpEdata);
    console.log("Index", index);
    this.editExstingLp(lpEdata);
  }


  goToNextPage() {
    if (this.selectedMskillsArr.length != -1) {
    this.newLpStep2 = true;
    this.newLpStep1 = false;
    this.hitTheGetCourseAPI();
    this.steptwoNxtbtn = "Create"
    }
  }

  hitTheGetCourseAPI(){
    this.tfrIds = [];
    if(this.selectedMskillsArr.length > 0){
      this.selectedMskillsArr.forEach(element => {
          this.tfrIds.push(element.pgSkillTrackMstr.skillTrackMstrId);
      });
    }
    if(this.editLpSkillTrackMstrIds.length > 0){
      console.log(this.editLpSkillTrackMstrIds);
      this.tfrIds = this.editLpSkillTrackMstrIds;
    }
    if (this.tfrIds.length > 0){
      this.getIds ='?skillIds=' +  this.tfrIds;
    }
    else{
    this.getIds ='?skillIds=' +  this.tfrIds[0];
    }
    if(this.tfrIds.length > 0){
    this.getBnyCourseDetails(this.getIds);
    }
  }

  getBnyCourseDetails(selectedSkill) {
    this.loader = true;
    this.employeeHttpService.getBNYEmployeeCourseDetails(selectedSkill).subscribe(response => {
      this.coursesLists = response;
      this.allCourses = response.allCourses;
      this.businessAssessment = response.businessAssessment;
      this.technicalAssessment = response.technicalAssessment;
      this.primaryAssessment = response.primaryAssessment;
      this.allReservedCourses = response.allCourses;
      this.businessReservedAssessment = response.businessAssessment;
      this.technicalReservedAssessment = response.technicalAssessment;
      this.primaryReservedAssessment = response.primaryAssessment;
      this.skillMstrIds = response.skillMstrIds;
      if (this.localStorageService.get('serachedText')) {
        this.selectedSkill = _.filter(this.skills, (v) => _.includes(this.skillMstrIds, v.skillTrackMstrId));
      }

      this.getCourseCount(response);
      this.loader = false;
      if(this.editLpSkillTrackMstrIds.length > 0){
        // this.selectedCourses = []
        this.allCourses.forEach(element => {
          this.editLpcourseIds.forEach(x => {
            if(element.courseDetailsId == x.id){
              element.selected = true;
            }
          });
        });

        this.businessAssessment.forEach(element => {
          this.editLpbusinessAssIds.forEach(y => {
            if(element.id == y.id){
              element.selected = true;
            }
          });
        });

        this.technicalAssessment.forEach(element => {
          this.editLptechnicalAssIds.forEach(t => {
            if(element.id == t.id){
              element.selected = true;
            }
          });
        });

        this.primaryAssessment.forEach(element => {
          this.editLpprimaryAssIds.forEach(p => {
            if(element.assessmentId == p.id){
              element.selected = true;
            }
          });
        });

        this.selectedCourses.length = this.editLpObjCount;
        this.steptwoNxtbtn = 'Update'
      }
    }, () => {
        this.loader = false;
        this.allCourses = [];
        this.primaryAssessment = [];
        this.technicalAssessment = [];
        this.businessAssessment = [];
      });
  }
  getCourseCount(courseList) {
    this.tabDetails.forEach((data) => {
      if (data.containerText === 'Courses') {
        data.count = courseList.allCourses.length;
      } else if (data.containerText === 'Primary Assessment') {
        data.count = courseList.primaryAssessment.length;
      } else if (data.containerText === 'Technical Assessment') {
        data.count = courseList.technicalAssessment.length;
      } else if (data.containerText === 'Business Assessment') {
        data.count = courseList.businessAssessment.length;
      }
    })
  }

  selectCourse(course: any = {}, category) {
    if (course.selected) {
      course.selected = false;
      if (category === 'course') {
        this.allSelectedCourses = this.allSelectedCourses.filter(item => item.courseDetailsId !== course.courseDetailsId);
      } else if (category === 'Primary') {
        this.primarySelectedAssessment = this.primarySelectedAssessment.filter(item => item.assessmentId !== course.assessmentId);
      } else if (category === 'Technical') {
        this.technicalSelectedAssessment = this.technicalSelectedAssessment.filter(item => item.id !== course.id);
      } else if (category === 'Business') {
        this.businessSelectedAssessment = this.businessSelectedAssessment.filter(item => item.id !== course.id);
      }
      this.selectedCourses = this.selectedCourses.filter(item => item.courseId !== course.courseDetailsId);
    } else {
      course.selected = true;
      if (category === 'course') {
        this.allSelectedCourses.push(course);
      } else if (category === 'Primary') {
        this.primarySelectedAssessment.push(course)
      } else if (category === 'Technical') {
        this.technicalSelectedAssessment.push(course)
      } else if (category === 'Business') {
        this.businessSelectedAssessment.push(course)
      }
      this.selectedCourses.push({ 'courseId': course.courseDetailsId, "assessment": course.assessment });
    }
  }

  editSelectedCourse(course: any = {}, category) {
    if (course.selected) {
      course.selected = false;
    }
    else{
      course.selected = true;
    }
  }

  deleteSelectedCourse(course: any = {}, category) {
    if (category === 'course') {
      this.allSelectedCourses = this.allSelectedCourses.filter(item => item.courseDetailsId !== course.courseDetailsId);
    } else if (category === 'Primary') {
      this.primarySelectedAssessment = this.primarySelectedAssessment.filter(item => item.assessmentId !== course.assessmentId);
    } else if (category === 'Technical') {
      this.technicalSelectedAssessment = this.technicalSelectedAssessment.filter(item => item.id !== course.id);
    } else if (category === 'Business') {
      this.businessSelectedAssessment = this.businessSelectedAssessment.filter(item => item.id !== course.id);
    }
  }

  displaySelectedCats() {
    if (this.showcatdispDiv == false) {
      this.showcatdispDiv = true;
    }
    else if (this.showcatdispDiv == true) {
      this.showcatdispDiv = false;
    }

  }
  smoothScroll(target) {
    let scrollContainer = target;
    do { // find scroll container
      scrollContainer = scrollContainer.parentNode;
      if (!scrollContainer) return;
      scrollContainer.scrollTop += 1;
    } while (scrollContainer.scrollTop === 0);

    let targetY = 0;
    do { // find the top of target relatively to the container
      if (target == scrollContainer) break;
      targetY += target.offsetTop;
    } while (target = target.offsetParent);

    var scroll = function (c, a, b, i) {
      i++; if (i > 30) return;
      c.scrollTop = a + (b - a) / 30 * i;
      setTimeout(function () { scroll(c, a, b, i); }, 20);
    }
    // start scrolling
    scroll(scrollContainer, scrollContainer.scrollTop, targetY, 20);
  }

  goToPrevLpPage(){
    this.newLpStep2 = false;
    this.newLpStep1 = true;
  }

  deleteSkillCourse(skillData) {
    if (this.selectedMskillsArr.length > 0) {
      this.selectedMskillsArr.forEach((element, index) => {
        if (element.pgSkillTrackMstr.skillTrackMstrId === skillData.pgSkillTrackMstr.skillTrackMstrId) {
          this.selectedMskillsArr.splice(index, 1);
        }
      });
      this.hitTheGetCourseAPI();
    }
    if(this.selectedMskillsArr.length == 0){
      this.goToPrevLpPage();
      // this.selected = false;
    }
  }

  submitLpCourseData() {
    console.log("allSelectedCourses", this.allSelectedCourses);
    console.log("primarySelectedAssessment", this.primarySelectedAssessment);
    console.log("technicalSelectedAssessment", this.technicalSelectedAssessment);
    console.log("businessSelectedAssessment", this.businessSelectedAssessment);
    this.newLpStep3 = true;
    this.newLpStep2 = false;
    this.newLpStep1 = false;
  }

  CreateNewLp(){
    // this.courseIds = []
    if(this.allSelectedCourses.length > 0){
      let courseIds = [];
      this.allSelectedCourses.forEach(element => {
      courseIds.push({id:element.courseDetailsId , skillId:element.skillTrackId})
    });
    this.newLpReqs.courseIds = courseIds;
    }

    if(this.primarySelectedAssessment.length > 0 ){
      let primaryAssIds = [];
      this.primarySelectedAssessment.forEach(element => {
        primaryAssIds.push({id:element.assessmentId , skillId:element.pgSkillTrackMstr.skillTrackMstrId})
      });
      this.newLpReqs.primaryAssIds = primaryAssIds;
    }

    if(this.technicalSelectedAssessment.length > 0){
      let technicalAssIds = [];
      this.technicalSelectedAssessment.forEach(element => {
        technicalAssIds.push({id: element.id, skillId: element.skillTrackMstrId})
      });
      this.newLpReqs.technicalAssIds = technicalAssIds;
    }

    if(this.businessSelectedAssessment.length > 0){
      let businessAssIds = [];
      this.businessSelectedAssessment.forEach(element => {
        businessAssIds.push({id: element.id, skillId: element.skillTrackMstrId})
      });
      this.newLpReqs.businessAssIds = businessAssIds;
    }
    if(this.reqData.emailId){
    this.newLpReqs.userEmail = this.reqData.emailId;
    }
    if(this.reqData.email){
      this.newLpReqs.userEmail = this.reqData.email;
      }
    this.newLpReqs.userInfoMstrId = this.reqData.userInfoMstrId;

    this.AuthService.createLearingPath(this.newLpReqs).then(resp =>{
      console.log(resp,'create new Learning path');
      if (!resp.learningPath.successMessage) {
        this.errMsg = [resp.error, resp.message];
        console.log("this.errMsg --- ", this.errMsg);
        this.toastr.error("Error while creating the learning path.");
      }
      else {
      this.lpConfData = resp;
      this.newLpStep3 = false;
      this.newLearningPath = true;
      this.successLpPage = true;
      this.lpEntryStatus = "Created";
      this.newLpReqs = {};
      }
    }
    ).catch(err =>{
      console.log(err)
    })
  }

  viewAllLps(){
    this.newLpStep1 = false;
    this.newLpStep2 = false;
    this.newLpStep3 = false;
    this.successLpPage = false;
    this.newLearningPath = false;
    this.viewDetLpInfo = false;
    this.getAllLearningPath();
  }

  editExstingLp(e){
    this.learningPathId = e.id;
    this.editLpSkillTrackMstrIds = e.skillIds;
    this.editLpbusinessAssIds = e.businessAssIds;
    this.editLpcourseIds = e.courseIds;
    this.editLpprimaryAssIds = e.primaryAssIds;
    this.editLptechnicalAssIds = e.technicalAssIds;
    if(this.editLpbusinessAssIds === undefined){
      this.editLpbusinessAssIds = [];
      console.log(1111);
    }
    if(this.editLpcourseIds === undefined){
      this.editLpcourseIds = [];
      console.log(2222);
    };
    if(this.editLpprimaryAssIds === undefined){
      this.editLpprimaryAssIds = [];
      console.log(3333);
    };
    if(this.editLptechnicalAssIds === undefined){
      this.editLptechnicalAssIds = [];
      console.log(4444);
    };

     this.editLpObjCount = this.editLpbusinessAssIds.length + this.editLpcourseIds.length + this.editLpprimaryAssIds.length + this.editLptechnicalAssIds.length;
    this.AuthService.getSelectedLearningPath(this.learningPathId).then(resp => {
      console.log(resp,'selected Learning path details');
      this.theSelectedLearningPath = resp.learningPath;
      this.newLpReqs.name = this.theSelectedLearningPath.name;
      this.newLpReqs.pgExperienceLevelId = this.theSelectedLearningPath.pgExperienceLevelId;
      this.newLpReqs.description = this.theSelectedLearningPath.description;

    });

    let onlyCIds = [];
    e.courseIds.forEach(element => {
      onlyCIds.push(element.id);
    });
    this.AuthService.getCourseByCourseIds(onlyCIds).then(resp => {
      console.log("coureses resp by ID", resp);
      this.allSelectedCourses = resp.courseDetails;
    })

    let assBasedOnIds:any = {};

    if(e.primaryAssIds && e.primaryAssIds.length > 0){
      let primaryAssIds = [];
      e.primaryAssIds.forEach(element => {
        primaryAssIds.push(element.id);
      });
      assBasedOnIds.primaryAssIds = primaryAssIds;
    }

    if(e.technicalAssIds && e.technicalAssIds.length > 0){
      let technicalAssIds = [];
      e.technicalAssIds.forEach(element => {
        technicalAssIds.push(element.id);
      });
      assBasedOnIds.technicalAssIds = technicalAssIds;
    }

    if(e.businessAssIds && e.businessAssIds.length > 0){
      let businessAssIds = [];
      e.businessAssIds.forEach(element => {
        businessAssIds.push(element.id);

      });
      assBasedOnIds.businessAssIds = businessAssIds;
    }

    this.AuthService.getAllAssesmentsById(assBasedOnIds).then(resp => {
      console.log("resp - ass by IDs --", resp);
      if(resp.primaryAssList){
        this.primarySelectedAssessment = resp.primaryAssList;
      }
      if(resp.technicalAssList){
        this.technicalSelectedAssessment = resp.technicalAssList;
      }
      if(resp.businessAssList){
        this.businessSelectedAssessment = resp.businessAssList;
      }
    });

    this.newLearningPath = true;
    this.newLpStep1 = false;
    this.newLpStep3 = true;
    this.isLpUpdate = true;
    this.skFormTitle = 'Edit Learning Path';
  }

  UpdateNewLp(){
    if(this.allSelectedCourses.length > 0){
      let courseIds = [];
      this.allSelectedCourses.forEach(element => {
      courseIds.push({id:element.courseDetailsId , skillId:element.skillTrackId})
    });
    this.newLpReqs.courseIds = courseIds;
    }

    if(this.primarySelectedAssessment.length > 0 ){
      let primaryAssIds = [];
      this.primarySelectedAssessment.forEach(element => {
        primaryAssIds.push({id:element.assessmentId , skillId:element.pgSkillTrackMstr.skillTrackMstrId})
      });
      this.newLpReqs.primaryAssIds = primaryAssIds;
    }

    if(this.technicalSelectedAssessment.length > 0){
      let technicalAssIds = [];
      this.technicalSelectedAssessment.forEach(element => {
        technicalAssIds.push({id: element.id, skillId: element.skillTrackMstrId})
      });
      this.newLpReqs.technicalAssIds = technicalAssIds;
    }

    if(this.businessSelectedAssessment.length > 0){
      let businessAssIds = [];
      this.businessSelectedAssessment.forEach(element => {
        businessAssIds.push({id: element.id, skillId: element.skillTrackMstrId})
      });
      this.newLpReqs.businessAssIds = businessAssIds;
    }

    if(this.reqData.emailId){
      this.newLpReqs.userEmail = this.reqData.emailId;
    }
    if(this.reqData.email){
      this.newLpReqs.userEmail = this.reqData.email;
    }
    this.newLpReqs.userInfoMstrId = this.reqData.userInfoMstrId;
    this.newLpReqs.id = this.learningPathId;
    console.log("editLprequest Object -- ", this.newLpReqs);

    this.AuthService.editLearningPath(this.newLpReqs).then((resp:any) => {
      resp = JSON.parse(resp.message);
      // resp =  JSON.parse(resp._body);
      if(resp.status == "error" || (resp.learningPath.errorBean && resp.learningPath.errorBean.code == "INUSE")){
        this.toastr.error("Cannot Edit as Learning Path is already in use and Active");
      }
      else{
        this.toastr.success("Learning Path Updated Successfully !!");
        // this.getAllLearningPath();
        // }
        // if(resp.status == 'success'){
        this.newLpStep3 = false;
        this.newLearningPath = true;
        this.successLpPage = true;
        this.lpEntryStatus = "Updated";
      }
    })
  }

  deleteExistingLp(e){
    console.log("delete event --", e);
    // if (e.isDelete) {
      document.getElementById("delLpModal").click();
      //this.confirmDelete
    // }
    this.learningPathId = e.id;
    this.userInfoMstrId = this.reqData.userInfoMstrId
  }
  confirmDelete(){
    console.log("LP ID --", this.learningPathId);
    console.log("Usr ID --", this.userInfoMstrId)
    this.AuthService.deleteLearningPath(this.learningPathId, this.userInfoMstrId).subscribe((resp:any) => {
      resp =  JSON.parse(resp._body);
      console.log("to delete lp - resp -- ",resp);
      if(resp.learningPath.errorBean && resp.learningPath.errorBean.code == "INUSE"){
        this.toastr.error("Cannot Delete as Learning Path is already in use and Active");
      }
      else{
      this.toastr.success("Learning Path Deleted Successfully !!");
      this.getAllLearningPath();
      }
    })
  }

  addMoretoLp(){
    this.newLpStep3 = false;
    this.hitTheGetCourseAPI();
    this.newLpStep2 = true;
  }

  cancelForm(){
    this.newLpReqs = {};
    this.newLearningPath = false;
    this.newLpStep1 = true;
  }

  viewDetailedLp(e){
    console.log(e);
    this.viewLpDetData = e;
    this.editExstingLp(e);
    this.newLearningPath = false;
    this.newLpStep1 = false;
    this.newLpStep3 = false;
    this.isLpUpdate = false;


    this.viewDetLpInfo = true;
    this.skFormTitle = 'View Learning Path';
  }

  resetFilter(e){
    this.learningPathList = [];
    this.learningPathList = this.learningPathListCopy;
    this.setPage(1);
  }

  filteredArrList(e){
    console.log("passed filteredArrList --- ",e);
      this.learningPathList = this.learningPathListCopy.filter(function (item, index, array) {
        return e.levelFilter.length > 0 ? e.levelFilter.includes(item.pgExperienceLevelName) : true;
      }).filter(function (item, index, array) {
        if (e.skillFilter.length > 0) {
          return _.intersection(e.skillFilter, item.skillNames).length > 0;
        } else {
          return true;
        }
      });

    console.log(this.learningPathList);
    this.setPage(1);

  }

  sortFn(data){
    console.log(data);
  }
}


interface Explevel {
  id: number,
  level : string
}
