import { Component, OnInit } from '@angular/core';
import { HyperService } from '../../core/services/http.service';
import { Router } from "@angular/router";
import { LocalStorage } from '../../core/services/local_storage.service';

@Component({
  selector: 'app-myassessment',
  templateUrl: './myassessment.component.html',
  styleUrls: ['./myassessment.component.scss']
})
export class MyassessmentComponent implements OnInit {
  assessement_list: any = [];
  loader: boolean;
  constructor(private server: HyperService, private router: Router) {}

  ngOnInit() {
      this.getAssessmentList();
  }

  getAssessmentList() {
      this.loader = true
      this.server.get("assessment")
          .then((data) => {
              if (data.status == 200 && data.result.response != 'failed') {
                  this.assessement_list = data.result.data;
                  this.loader = false
                  LocalStorage.setValue('assessement_list', this.assessement_list);
              } else if (data.result.status == 401 && data.result.response == 'failed') {}
          });
  }

  onSelect(list) {
      if (list.status == 8) {
          alert('Assessment is expired. Please contact admin')
      } else if (list.attemptslimit == list.attempt_time) {
          alert("Assessment limit is over")
      } else {
          console.log(list)
          LocalStorage.setValue('selected_assessment', list)
          this.router.navigateByUrl('assessment/' + list.assessmentid);
      }
  }

}