import { NavigationService } from '../navigation.service';
import { Component, OnInit } from '@angular/core';
import { AuthService } from '../services/auth.service';
import { LocalStorageService } from 'angular-2-local-storage';
import { Router, NavigationStart } from '@angular/router';
import { environment } from '../../environments/environment.dev';

@Component({
  selector: 'app-introduction',
  templateUrl: './introduction.component.html',
  styleUrls: ['./introduction.component.css' ]
})
export class IntroductionComponent implements OnInit {
  sessionDetails = {};
  userDetails: {
    fullName: string[]
  };
  output: any;
  reqData: any;
  userName: any;
  candidateVid: any;
  currentSlide: any;
  // vid_path = '../assets/videos';
  imageUrl: string = environment.imageUrl;
  constructor (protected localStorageService: LocalStorageService, private AuthService: AuthService, private router: Router) {
  }

  ngOnInit() {
    const reqData = {};
    this.reqData = this.localStorageService.get('authToken');
    this.sessionDetails = this.localStorageService.get('authUserDetails');
    console.log(this.sessionDetails, this.reqData);

    this.AuthService.userDetails(this.reqData).then(resp => {
      this.output = JSON.parse(resp);
      this.reqData.fullName = this.output.infoDetails.userInfoMstr.fullName;
      this.reqData.adId = this.output.infoDetails.adId;
      this.reqData.level = this.output.infoDetails.experienceInYrs ||  this.output.infoDetails.experienceLevel;
      this.reqData.email = this.output.infoDetails.emailId;
      this.reqData.userInfoMstrId = this.output.infoDetails.userInfoMstrId;
      this.localStorageService.set('authToken', this.reqData);
      this.userName = this.reqData['fullName'];

      if (this.output) {
        this.userDetails = this.output.infoDetails;
      } else {

      }
    }).catch(err => {
      console.log(JSON.stringify(err));
    });
    this.candidateVid = 'https://pgvideos.altimetrik.com/Candidate.mov';
    this.currentSlide = 1;
  }

  selectSlide(index) {
    this.setCurrentSlide(index);
  }

  previousSlide() {
    if (this.currentSlide !== 1) {
      this.setCurrentSlide(this.currentSlide - 1);
    } else {
      return;
    }
  }

  nextSlide() {
    if (this.currentSlide !== 5) {
      this.setCurrentSlide(this.currentSlide + 1);
    } else {
      this.router.navigate(['dashboard']);
    }
  }

  setCurrentSlide(index) {
    this.currentSlide = index;
  }

}
