import {
  Component,
  OnInit,
} from '@angular/core';
import { ServicesService } from '../../services.service';
import { Router, ActivatedRoute } from '@angular/router';
import { NgxSpinnerService } from 'ngx-spinner';
import { AuthserviceService } from '../../authservice.service';
import { CatexamService } from '../../services/CAT/catexam.service';

@Component({
  selector: 'app-cateexamtestque',
  templateUrl: './cateexamtestque.component.html',
  styleUrls: ['./cateexamtestque.component.scss'],
})
export class CateexamtestqueComponent implements OnInit {
  userid: any;
  testid: any;
  PracticeQuestionlist = [];
  NextPracticeQuestionArray = [];
  NextChnageQuestionNo = 0;
  DomainReport = [];
  QuestionLen = 0;
  AnsValue = 0;
  AnswerComplter = 0;
  correct = 0;
  incorrct = 0;
  calhid = false;
  IsCalcOpen: boolean = false;
  data: any;
  name: any;
  IsAcronyOpen: boolean = false;
  Seconds: any;
  Minutes: any;
  Hour: any;
  interval = true;
  acronymslist = [];
  VERYSIMPLE = [];
  SIMPLE = [];
  AVERAGE = [];
  ABOVEAVERAGE = [];
  HARD = [];
  DIFFCULT = [];
  TRICKY = [];
  VERYSIMPLECount = 0;
  SIMPLECount = 0;
  AVERAGECount = 0;
  ABOVEAVERAGECount = 0;
  HARDCount = 0;
  DIFFCULTCount = 0;
  TRICKYCount = 0;
  TotalCurrentQuestion = 0;
  currenttype;
  currentTypeCount = 0;
  ShowStartQuestion = [];
  AllCounter = 0;
  newCounter = 1;
  loading = true;
  constructor(
    public CatexamService: CatexamService,
    public auth: AuthserviceService,
    public service: ServicesService,
    public spinner: NgxSpinnerService,
    public ActiveRoute: ActivatedRoute,
    public router: Router
  ) {
    var setlogin = this.auth.isLoggedIn();
    if (!setlogin) {
      this.router.navigate(['/login']);
      this.spinner.hide();
    }
    this.service.headershow = true;
    this.service.SearchValue = false;
    var access = window.localStorage.getItem('accessitem');
    if (access) {
      var set = JSON.parse(<string>access);
      if (set) {
        this.service.access.CATaccess = set.CAT_access ? true : false;
        this.service.access.Knowaccess = set.KA_access ? true : false;
        this.service.access.Practiceaccess = set.PT_access ? true : false;
        this.service.access.livechat_access = set.livechat_access ? true : false;
      }
    }
    this.userid = localStorage.getItem('CisspUserId');
    this.ActiveRoute.params.subscribe(async (params) => {
      try {
        this.testid = JSON.parse(atob(decodeURIComponent(params['testid'])));
      } catch (error) {
        this.router.navigate(['sidenav/cateexamtest']);
      }
    });
    this.service.headerset = {
      dashboard: false,
      studyguuide: false,
      knowledge: false,
      practice: false,
      cat: false,
      datestring: false,
      CATresult: false,
      CATQue: false,
      PracticeResult: false,
      Practiceques: false,
      knowques: false,
      knowresult: false,
      studentprofile: false,
      resource: false,
      liveSupport: false
    };
  }
  ngOnDestroy() {
    this.interval = false;
  }
  leftPad(number, targetLength) {
    var output = number + '';
    while (output.length < targetLength) {
      output = '0' + output;
    }
    return output;
  }
  showTime() {
    this.Seconds--;
    this.Seconds = this.leftPad(this.Seconds, 2);
    if (this.Seconds < 0) {
      this.Seconds = 59;
    }
    if (this.Seconds == 59) {
      this.Minutes--;
      this.Minutes = this.leftPad(this.Minutes, 2);
    }
    if (this.Minutes < 0) {
      this.Minutes = 59;
    }
    if (this.Minutes == 59 && this.Seconds == 59) {
      this.Hour--;
      this.Hour = this.leftPad(this.Hour, 2);
    }
  }
  async ngOnInit() {
    await this.spinner.show();
    var data = localStorage.getItem('userdetails');
    if (data != undefined || data != null || data != '') {
      this.data = JSON.parse(<string>data);
      this.name = this.data.aliasname
        ? this.data.aliasname + "'s"
        : this.data.name + "'s";
      this.service.title =
        "<p class='HeaderUser'>" +
        this.name +
        '<span> CAT Exam Test </span></p>';
    }

    await this.listPracticeTestQuestion();
    await this.acronymslistdata();
    if (this.NextPracticeQuestionArray.length > 0) {
      if ((this.interval = true)) {
        setInterval(() => {
          this.showTime();
        }, 1000);
      }
    }
  }
  async listPracticeTestQuestion() {
    this.AnswerComplter = 0;
    this.PracticeQuestionlist = [];
    try {
      var authenticatedUser = this.auth.getAuthenticatedUser();
      await this.auth
        .getAuthenticatedUser()
        .getSession(async (err, session) => {
          if (err) {
            await this.spinner.hide();
            this.router.navigate(['/login']);
          } else {
            this.correct = 0;
            this.incorrct = 0;
            var token = session
            var cohort_id = localStorage.getItem('cohort_id');
            await this.CatexamService.CateExamFiltertestques(
              this.userid,
              this.testid,
              cohort_id,
              token
            ).then(async (data) => {
              if (data[0].status == 200) {
                var list = JSON.parse(<string>data[0].json);
                this.PracticeQuestionlist = list.data;
              }
              this.QuestionLen = this.PracticeQuestionlist.length;
              this.NextChnageQuestionNo = 0;
              this.AnswerComplter = this.AnswerComplter + 1;
              if (this.PracticeQuestionlist.length > 0) {
                this.PracticeQuestionlist.forEach((element) => {
                  element['displayquesion'] = false;
                  if (element.answered == 1) {
                    if (element.user_ans == element.answer) {
                      this.correct = this.correct + 1;
                    } else {
                      this.incorrct = this.incorrct + 1;
                    }
                  }
                });
                this.VERYSIMPLE = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'VERY SIMPLE'
                );
                this.SIMPLE = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'SIMPLE'
                );
                this.AVERAGE = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'AVERAGE'
                );
                this.ABOVEAVERAGE = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'ABOVE AVERAGE'
                );
                this.HARD = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'HARD'
                );
                this.DIFFCULT = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'DIFFICULT'
                );
                this.TRICKY = this.PracticeQuestionlist.filter(
                  (x) => x.type == 'TRICKY'
                );

                if (this.VERYSIMPLE.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.VERYSIMPLE.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.VERYSIMPLE;
                  }
                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.VERYSIMPLECount]
                  );
                  this.VERYSIMPLECount++;
                } else if (this.SIMPLE.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.SIMPLE.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.SIMPLE;
                  }

                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.SIMPLECount]
                  );
                  this.SIMPLECount++;
                } else if (this.AVERAGE.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.AVERAGE.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.AVERAGE;
                  }
                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.AVERAGECount]
                  );
                  this.AVERAGECount++;
                } else if (this.ABOVEAVERAGE.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.ABOVEAVERAGE.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.ABOVEAVERAGE;
                  }
                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.ABOVEAVERAGECount]
                  );
                  this.ABOVEAVERAGECount++;
                } else if (this.HARD.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.HARD.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.HARD;
                  }
                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.HARDCount]
                  );
                  this.HARDCount++;
                } else if (this.DIFFCULT.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.DIFFCULT.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.DIFFCULT;
                  }
                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.DIFFCULTCount]
                  );
                  this.DIFFCULTCount++;
                } else if (this.TRICKY.length > 0) {
                  if (this.VERYSIMPLE.length >= 10) {
                    this.ShowStartQuestion = this.TRICKY.slice(0, 10);
                  } else {
                    this.ShowStartQuestion = this.TRICKY;
                  }
                  this.NextPracticeQuestionArray.push(
                    this.ShowStartQuestion[this.TRICKYCount]
                  );
                  this.TRICKYCount++;
                }
              }
              this.AllCounter++;
              await this.spinner.hide();
            });
          }
        });
    } catch (e) {
      await this.spinner.hide();
      this.service.ShowError(e.meassage);
    }
  }
  async QuestionClick(item, index: number) {
    this.NextPracticeQuestionArray = [];
    this.NextPracticeQuestionArray.push(item);
    this.NextChnageQuestionNo = index - 1;
  }
  async NextClick(item) {
    this.newCounter++;
    if (this.AnsValue != 0) {
      item.answered = 1;
      item.user_ans = this.AnsValue;
      this.NextPracticeQuestionArray = [];
      this.NextChnageQuestionNo = this.NextChnageQuestionNo + 1;

      this.auth.getAuthenticatedUser().getSession(async (err, session) => {
        if (err) {
          this.router.navigate(['/login']);
        } else {
          var token = session
          var correct = item.user_ans === item.answer ? 1 : 0;
          var cohort_id = localStorage.getItem('cohort_id');
          var time = this.leftPad(this.Hour, 2) + ':' + this.leftPad(this.Minutes, 2) + ':' + this.leftPad(this.Seconds, 2);
          await this.CatexamService.addcateexamtestans(
            this.userid,
            this.testid,
            item.id,
            this.AnsValue,
            token,
            correct,
            item.d_id,
            item.sd_id,
            item.topic_id,
            cohort_id,
            time
          ).then(async (data) => { });
        }
      });

      await this.NewModuleCat(item);
      this.AnsValue = 0;
    } else {
      if (item.user_ans != null && item.user_ans != 0) {
        this.NextPracticeQuestionArray = [];
        if (this.PracticeQuestionlist.length > 0) {
          this.AnswerComplter = this.AnswerComplter + 1;
          this.correct = 0;
          this.incorrct = 0;
          this.PracticeQuestionlist.forEach((element) => {
            if (element.answered == 1) {
              if (element.user_ans == element.answer) {
                this.correct = this.correct + 1;
              } else {
                this.incorrct = this.incorrct + 1;
              }
            }
          });
        }
        this.NextChnageQuestionNo = this.NextChnageQuestionNo + 1;
      }

      await this.NewModuleCat(item);
      this.AnsValue = 0;
    }
  }
  PreviousClick() {
    if (this.NextChnageQuestionNo != 0) {
      this.NextPracticeQuestionArray = [];
      this.NextChnageQuestionNo = this.NextChnageQuestionNo - 1;
      if (this.PracticeQuestionlist.length - 1 >= this.NextChnageQuestionNo) {
        this.NextPracticeQuestionArray.push(
          this.PracticeQuestionlist[this.NextChnageQuestionNo]
        );
      } else {
        this.viewresultset();
      }
    }
    this.AnsValue = 0;
  }
  AnswerPreTest(ans, items) {
    if (ans != 0 && !items.answered) {
      this.AnsValue = ans;
      items.user_ans = this.AnsValue;
    } else {
      this.AnsValue = 0;
      items.user_ans = this.AnsValue;
    }
  }
  viewresult() {
    var data = btoa(JSON.stringify(this.testid));
    data = encodeURIComponent(data);
    this.router.navigate([`sidenav/cateexamtestresult/${data}`]);
  }
  calhidden() {
    this.IsAcronyOpen = false;
    this.IsCalcOpen = !this.IsCalcOpen;
  }
  acroclick() {
    this.IsCalcOpen = false;
    this.IsAcronyOpen = !this.IsAcronyOpen;
  }
  async acronymslistdata() {
    try {
      await this.auth
        .getAuthenticatedUser()
        .getSession(async (err, session) => {
          if (err) {
            await this.spinner.hide();
            this.router.navigate(['/login']);
          } else {
            var token = session
            await this.CatexamService.IdCateExamTest(this.testid, token).then(
              async (value) => {
                if (value[0].status == 200) {
                  var list = JSON.parse(<string>value[0].json);
                  this.acronymslist = list.data.acronums;

                  if (
                    list.data.time != undefined &&
                    list.data.time != null &&
                    list.data.time != ''
                  ) {
                    if (list.data.time != 0) {
                      this.Hour = this.leftPad(parseInt(list.data.time.split(':')[0]), 2);
                      this.Minutes = this.leftPad(parseInt(list.data.time.split(':')[1]), 2);
                      this.Seconds = this.leftPad(0, 2);
                    } else {
                      this.Hour = this.leftPad(1, 2);
                      this.Minutes = this.leftPad(30, 2);
                      this.Seconds = this.leftPad(0, 2);
                    }
                  } else {
                    this.Hour = this.leftPad(1, 2);
                    this.Minutes = this.leftPad(30, 2);
                    this.Seconds = this.leftPad(0, 2);
                  }
                } else {
                  await this.spinner.hide();
                }
              }
            );
          }
        });
    } catch (e) {
      await this.spinner.hide();
      this.service.ShowError(e.meassage);
    }
  }
  NewModuleCat(item) {
    this.NextPracticeQuestionArray = [];
    if (item.type == 'VERY SIMPLE') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.VERYSIMPLECount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];
          if (this.SIMPLE.length > this.SIMPLECount && this.SIMPLE.length > 0) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        } else {
          this.ShowStartQuestion = [];
          if (
            this.VERYSIMPLE.length > this.VERYSIMPLECount &&
            this.VERYSIMPLE.length > 0
          ) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.SIMPLE.length > this.SIMPLECount &&
            this.SIMPLE.length > 0
          ) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        }
      }
    } else if (item.type == 'SIMPLE') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.SIMPLECount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];

          if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        } else {
          this.ShowStartQuestion = [];
          if (
            this.VERYSIMPLE.length > this.VERYSIMPLECount &&
            this.VERYSIMPLE.length > 0
          ) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.SIMPLE.length > this.SIMPLECount &&
            this.SIMPLE.length > 0
          ) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        } else {
        }
      }
    } else if (item.type == 'AVERAGE') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.AVERAGECount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];
          if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        } else {
          this.ShowStartQuestion = [];
          if (this.SIMPLE.length > this.SIMPLECount && this.SIMPLE.length > 0) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.VERYSIMPLE.length > this.VERYSIMPLECount &&
            this.VERYSIMPLE.length > 0
          ) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        }
      }
    } else if (item.type == 'ABOVE AVERAGE') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.ABOVEAVERAGECount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];
          if (this.HARD.length > this.HARDCount && this.HARD.length > 0) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        } else {
          this.ShowStartQuestion = [];
          if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.SIMPLE.length > this.SIMPLECount &&
            this.SIMPLE.length > 0
          ) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.VERYSIMPLE.length > this.VERYSIMPLECount &&
            this.VERYSIMPLE.length > 0
          ) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        }
      }
    } else if (item.type == 'HARD') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.HARDCount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];
          if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        } else {
          this.ShowStartQuestion = [];
          if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.SIMPLE.length > this.SIMPLECount &&
            this.SIMPLE.length > 0
          ) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.VERYSIMPLE.length > this.VERYSIMPLECount &&
            this.VERYSIMPLE.length > 0
          ) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        }
      }
    } else if (item.type == 'DIFFICULT') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.DIFFCULTCount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];
          if (this.TRICKY.length > this.TRICKYCount && this.TRICKY.length > 0) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        } else {
          this.ShowStartQuestion = [];
          if (this.HARD.length > this.HARDCount && this.HARD.length > 0) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.SIMPLE.length > this.SIMPLECount &&
            this.SIMPLE.length > 0
          ) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (this.VERYSIMPLECount && this.VERYSIMPLE.length > 0) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        }
      }
    } else if (item.type == 'TRICKY') {
      if (this.ShowStartQuestion.length > this.AllCounter) {
        this.NextPracticeQuestionArray.push(
          this.ShowStartQuestion[this.AllCounter]
        );
        this.DIFFCULTCount++;
        this.AllCounter++;
      } else {
        var correct = 0;
        var incorrect = 0;
        this.AllCounter = 0;
        this.ShowStartQuestion.forEach((element) => {
          if (element.user_ans == element.answer) {
            correct++;
          } else {
            incorrect++;
          }
        });
        if ((correct * 100) / this.ShowStartQuestion.length >= 50) {
          this.ShowStartQuestion = [];
          this.viewresultset();
        } else {
          this.ShowStartQuestion = [];
          if (
            this.DIFFCULT.length > this.DIFFCULTCount &&
            this.DIFFCULT.length > 0
          ) {
            if (this.DIFFCULTCount + 10 <= this.DIFFCULT.length) {
              this.ShowStartQuestion = this.DIFFCULT.slice(
                this.DIFFCULTCount,
                this.DIFFCULTCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.DIFFCULTCount,
                this.DIFFCULT.length
              );
            }
            this.DIFFCULTCount++;
          } else if (
            this.HARD.length > this.HARDCount &&
            this.HARD.length > 0
          ) {
            if (this.HARDCount + 10 <= this.HARD.length) {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARDCount + 10
              );
            } else {
              this.ShowStartQuestion = this.HARD.slice(
                this.HARDCount,
                this.HARD.length
              );
            }
            this.HARDCount++;
          } else if (
            this.ABOVEAVERAGE.length > this.ABOVEAVERAGECount &&
            this.ABOVEAVERAGE.length > 0
          ) {
            if (this.ABOVEAVERAGECount + 10 <= this.ABOVEAVERAGE.length) {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.ABOVEAVERAGE.slice(
                this.ABOVEAVERAGECount,
                this.ABOVEAVERAGE.length
              );
            }
            this.ABOVEAVERAGECount++;
          } else if (
            this.AVERAGE.length > this.AVERAGECount &&
            this.AVERAGE.length > 0
          ) {
            if (this.AVERAGECount + 10 <= this.AVERAGE.length) {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGECount + 10
              );
            } else {
              this.ShowStartQuestion = this.AVERAGE.slice(
                this.AVERAGECount,
                this.AVERAGE.length
              );
            }
            this.AVERAGECount++;
          } else if (
            this.SIMPLE.length > this.SIMPLECount &&
            this.SIMPLE.length > 0
          ) {
            if (this.SIMPLECount + 10 <= this.SIMPLE.length) {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.SIMPLE.slice(
                this.SIMPLECount,
                this.SIMPLE.length
              );
            }
            this.SIMPLECount++;
          } else if (
            this.VERYSIMPLE.length > this.VERYSIMPLECount &&
            this.VERYSIMPLE.length > 0
          ) {
            if (this.VERYSIMPLECount + 10 <= this.VERYSIMPLE.length) {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLECount + 10
              );
            } else {
              this.ShowStartQuestion = this.VERYSIMPLE.slice(
                this.VERYSIMPLECount,
                this.VERYSIMPLE.length
              );
            }
            this.VERYSIMPLECount++;
          } else if (
            this.TRICKY.length > this.TRICKYCount &&
            this.TRICKY.length > 0
          ) {
            if (this.TRICKYCount + 10 <= this.TRICKY.length) {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKYCount + 10
              );
            } else {
              this.ShowStartQuestion = this.TRICKY.slice(
                this.TRICKYCount,
                this.TRICKY.length
              );
            }
            this.TRICKYCount++;
          } else {
            this.ShowStartQuestion = [];
            this.viewresultset();
          }
        }
        if (this.ShowStartQuestion.length > 0) {
          this.NextPracticeQuestionArray.push(
            this.ShowStartQuestion[this.AllCounter]
          );
          this.AllCounter++;
        }
      }
    }
  }
  viewresultset() {
    var authenticatedUser = this.auth.getAuthenticatedUser();
    authenticatedUser.getSession(async (err, session) => {
      if (err) {
        this.router.navigate(['/login']);
      }
      this.auth.getAuthenticatedUser().getSession(async (err, session) => {
        if (err) {
          this.router.navigate(['/login']);
        } else {
          var token = session
          var cohort_id = localStorage.getItem('cohort_id');
          await this.CatexamService.catexamcomplate(
            this.userid,
            this.testid,
            token,
            cohort_id
          ).then((datas) => {
            var data = btoa(JSON.stringify(this.testid));
            data = encodeURIComponent(data);
            this.service.testlogs_add(
              this.userid,
              this.testid,
              'CAT',
              'END',
              token
            );
            this.router.navigate([`sidenav/cateexamtestresult/${data}`]);
          });
        }
      });
    });
  }
  retuey() {
    window.location.reload();
  }
}