import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { EmployeeHttpService } from 'app/services/employee/employee-http.service';
import { EmployeeNavBarService } from '../employee-nav-bar.service';
import { EmployeeCoursesSliderComponent } from '../../shared/employee-course-card/employee-course-card.component';
import { LocalStorageService } from 'angular-2-local-storage';
import { environment } from '../../../../environments/environment.dev'
const img_path_prefix = environment.imageUrl+'/assets/img/employee/shared/';
const img_path_suffix = '.png';

@Component({
  selector: 'app-employee-courses',
  templateUrl: './employee-courses.component.html',
  styleUrls: ['./employee-courses.component.css']
})
export class EmployeeCoursesComponent implements OnInit, OnDestroy {

  private $destroyed = new Subject();
  private currentUser: any;
  courses: any = [];
  recommendedCourses: any = [];
  courseListNames: string[] = [];

  constructor(
    private employeeNavBarService: EmployeeNavBarService,
    private employeeHttpService: EmployeeHttpService,
    private localStorageService: LocalStorageService
  ) {
    this.employeeNavBarService.setCurrentPage(1);
  }

  ngOnInit() {
    this.currentUser = this.localStorageService.get('userInfo') || {};
    this.employeeHttpService.getUserCoursesDashboard(this.currentUser.userInfoMstrId).takeUntil(this.$destroyed)
    .subscribe(data => {
      this.courses = data.userCourseMapping.Wishlist.map(course => course.pgCourseDetails);
      this.recommendedCourses = data.userCourseMapping.Recommended.map(course => course.pgCourseDetails);
    });
  }

  ngOnDestroy() {
    this.$destroyed.next();
    this.$destroyed.complete();
  }

}
