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';
export let browserRefresh = false;
import { PracticeserviceService } from '../../services/practice/practiceservice.service';

@Component({
  selector: 'app-practicetestquestion',
  templateUrl: './practicetestquestion.component.html',
  styleUrls: ['./practicetestquestion.component.scss'],
})
export class PracticetestquestionComponent 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;
  IsAcronyOpen: boolean = false;
  name: any;
  data: any;
  Seconds: any;
  Minutes: any;
  Hour: any;
  interval = true;
  acronymslist = [];

  examtype: any;
  subscription: any;
  nofound: boolean = true;
  reviewCount = 0;
  Reviewpopup = false;

  ReviewArray = [];
  bkparrayReviewArray = [];
  ShowflaggedSet = false;
  Showincomplete = false;
  EndExampopup = false;

  ViewResultbutton = false;
  isSaving: boolean = false;
  constructor(
    public auth: AuthserviceService,
    public service: ServicesService,
    public spinner: NgxSpinnerService,
    public ActiveRoute: ActivatedRoute,
    public router: Router,
    public route: ActivatedRoute,
    public PracticeserviceService: PracticeserviceService,
  ) {
    var setlogin = this.auth.isLoggedIn();
    if (!setlogin) {
      this.router.navigate(['/login']);
      this.spinner.hide();
    }
    this.userid = localStorage.getItem('CisspUserId');
    this.service.headershow = true;
    this.service.SearchValue = false;

    this.service.headerset = {
      dashboard: false,
      studyguuide: false,
      knowledge: false,
      practice: false,
      cat: false,
      datestring: false,
      CATresult: false,
      studentprofile: false,
      CATQue: false,
      PracticeResult: false,
      Practiceques: false,
      knowques: false,
      knowresult: false,
      resource: false,
      liveSupport: false
    };

    this.service.title = '';
    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.service.headerset = {
      dashboard: false,
      studyguuide: false,
      knowledge: false,
      practice: false,
      cat: false,
      datestring: false,
      CATresult: false,
      CATQue: false,
      PracticeResult: false,
      studentprofile: false,
      Practiceques: false,
      knowques: false,
      knowresult: false,
      resource: false,
      liveSupport: false
    };

    try {
      this.ActiveRoute.params.subscribe(async (params) => {
        this.testid = 0;
        var dataset = JSON.parse(atob(decodeURIComponent(params['testid'])));
        if (dataset == undefined || dataset == '' || dataset == null) {
          this.router.navigate(['sidenav/practicetest']);
        }
        this.testid = dataset.id;
      });
    } catch (error) {
      this.router.navigate(['sidenav/practicetest']);
    }
  }
  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);
    }
  }
  calhidden() {
    this.IsAcronyOpen = false;
    this.IsCalcOpen = !this.IsCalcOpen;
  }
  acroclick() {
    this.IsCalcOpen = false;
    this.IsAcronyOpen = !this.IsAcronyOpen;
  }

  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 : this.data.name;
      this.service.title =
        "<p class='HeaderUser'>" +
        this.name +
        " 's <span>Practice Test</span></p>";
    }
    await this.praticeIdWise();
    // comment and add inside praticeIdWise
    // await this.listPracticeTestQuestion();
    // await this.acronymslistdata();
    // await this.examtimeset(); 
  }
  async examtimeset() {
    var anstime = this.PracticeQuestionlist.filter((item) => item.ans_time);
    var AnswerComplter = this.PracticeQuestionlist.filter(
      (item) => item.answered == 1
    );
    this.AnswerComplter = AnswerComplter.length;
    if (anstime.length > 0) {
      this.NextPracticeQuestionArray = [];
      var record = anstime[anstime.length - 1];
      if (record) {
        if (this.PracticeQuestionlist.length == record.Srno) {
          this.NextChnageQuestionNo = record.Srno - 1;
          this.AnswerPreTest(record.answer, record);
        } else {
          this.NextChnageQuestionNo = record.Srno;
        }
        if (!this.NextChnageQuestionNo) {
          this.NextChnageQuestionNo = 0;
        }
      }

      this.Hour = record.ans_time.split(':')[0];
      this.Minutes = record.ans_time.split(':')[1];
      this.Seconds = record.ans_time.split(':')[2];

      this.Hour = this.leftPad(this.Hour, 2);
      this.Minutes = this.leftPad(this.Minutes, 2);
      this.Seconds = this.leftPad(this.Seconds, 2);

    }
    if (this.PracticeQuestionlist[this.NextChnageQuestionNo]) {
      this.NextPracticeQuestionArray.push(
        this.PracticeQuestionlist[this.NextChnageQuestionNo]
      );
    } else {
      this.NextChnageQuestionNo = 0;
      this.NextPracticeQuestionArray.push(
        this.PracticeQuestionlist[this.NextChnageQuestionNo]
      );
    }
    if (this.PracticeQuestionlist.length > 0) {
      var answeredlength = this.PracticeQuestionlist.filter(
        (itemque) => itemque.answered == 0
      );
      if (answeredlength.length == 0) {
        this.ViewResultbutton = true;
      } else {
        this.ViewResultbutton = false;
      }
    }
    if ((this.interval = true)) {
      setInterval(() => {
        this.showTime();
      }, 1000);
    }
  }
  async listPracticeTestQuestion() {
    this.AnswerComplter = 0;
    this.PracticeQuestionlist = [];
    try {
      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.PracticeserviceService.getPracticeTestQuestions(
              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.nofound = true;
                this.PracticeQuestionlist.sort(
                  (a, b) => a.seq_number - b.seq_number
                );
                await this.PracticeQuestionlist.forEach((element, index) => {
                  element['Srno'] = index + 1;
                  if (element.answered == 1) {
                    this.correct = this.correct + 1;
                  }
                  if (element.flag_review == 1) {
                    this.reviewCount += 1;
                  }
                });
              } else {
                this.nofound = false;
              }
              await this.acronymslistdata();
              await this.spinner.hide();
            });
          }
        });
    } catch (e) {
      await this.spinner.hide();
      this.service.ShowError(e.meassage);
    }
  }
  async praticeIdWise() {
    await this.auth.getAuthenticatedUser().getSession(async (err, session) => {
      if (err) {
        this.router.navigate(['/login']);
      } else {
        var token = session
        await this.PracticeserviceService.PracticeidWise(
          this.testid,
          token
        ).then(async (data) => {
          if (data[0].status == 200) {
            var list = JSON.parse(<string>data[0].json);
            if (list.data.type) {
              this.examtype = list.data.type;
            } else {
              this.examtype = 'LINEAR';
            }
            await this.listPracticeTestQuestion();
          }
        });
      }
    });
  }
  review(items) {
    if (!items.flag_review || items.flag_review == 0) {
      items.flag_review = 1;
      this.reviewCount += 1;
    } else {
      items.flag_review = 0;
      this.reviewCount -= 1;
    }
  }
  async QuestionClick(item, index: number) {
    this.NextPracticeQuestionArray = [];
    this.NextPracticeQuestionArray.push(item);
    this.NextChnageQuestionNo = index - 1;
  }
  async NextClick(item) {
    if (this.examtype == 'LINEAR') {
      if (this.AnsValue != 0) {
        item.answered = 1;
      }
      if (item.user_ans) {
        this.AnsValue = item.user_ans;
      }

      await this.auth
        .getAuthenticatedUser()
        .getSession(async (err, session) => {
          if (err) {
            this.router.navigate(['/login']);
            await this.spinner.hide();
          } else {
            var token = session
            if (this.AnsValue != 0) {
              item.user_ans = this.AnsValue;
              var correct = item.answer === item.user_ans ? 1 : 0;

              if (!item.flag_review) {
                item.flag_review = 0;
              }
              var cohort_id = localStorage.getItem('cohort_id');
              var time = this.Hour + ':' + this.Minutes + ':' + this.Seconds;
              try {
                await this.PracticeserviceService.addpracticetestans(
                  this.userid,
                  this.testid,
                  item.id,
                  this.AnsValue,
                  token,
                  correct,
                  item.d_id,
                  item.sd_id,
                  item.topic_id,
                  item.flag_review,
                  cohort_id,
                  time
                ).then(async (data) => {
                  if (data && data[0] && data[0].status == 200) {
                    var testdata = JSON.parse(<string>data[0].json);
                    if (testdata.data.PTQ_id == item.id && testdata.data.user_id == this.userid && testdata.data.test_id == this.testid && testdata.data.cohort_id == cohort_id) {
                      if (this.PracticeQuestionlist.length > 0) {
                        this.NextPracticeQuestionArray = [];
                        if (
                          this.PracticeQuestionlist.length - 1 >
                          this.NextChnageQuestionNo
                        ) {
                          var arrayIndex = this.PracticeQuestionlist.findIndex(element => element.id == item.id);
                          if (arrayIndex == this.NextChnageQuestionNo) {
                            this.NextChnageQuestionNo = this.NextChnageQuestionNo + 1;
                          }
                        }
                        if (
                          this.PracticeQuestionlist.length > this.AnswerComplter
                        ) {
                          this.AnswerComplter = this.AnswerComplter + 1;
                        }
                        this.correct = 0;
                        this.incorrct = 0;
                        this.PracticeQuestionlist.forEach((element) => {
                          if (element.answered == 1) {
                            this.correct = this.correct + 1;
                          }
                        });

                        var answeredlength = this.PracticeQuestionlist.filter(
                          (itemque) => itemque.answered == 0
                        );
                        if (answeredlength.length == 0) {
                          this.viewresult();

                          this.ViewResultbutton = true;
                        } else {
                          this.ViewResultbutton = false;
                        }
                        if (
                          this.PracticeQuestionlist.length - 1 >=
                          this.NextChnageQuestionNo
                        ) {
                          this.NextPracticeQuestionArray.push(
                            this.PracticeQuestionlist[this.NextChnageQuestionNo]
                          );
                        } else {
                          if (answeredlength.length > 0) {
                            this.NextPracticeQuestionArray.push(
                              answeredlength[0]
                            );
                          }
                          else {
                            this.NextPracticeQuestionArray.push(
                              this.PracticeQuestionlist[
                              this.PracticeQuestionlist.length - 1
                              ]
                            );
                          }
                        }
                        this.AnsValue = 0;
                        this.IsCalcOpen = false;
                      }
                    }
                    else {

                      this.service.ShowError('Please try again.');
                      item.answered = null;
                      item.user_ans = null;
                    }
                  } else {
                    item.answered = null;
                    item.user_ans = null;
                    await this.spinner.hide();

                    this.service.ShowError('Please try again.');
                  }
                });
              } catch {
                item.answered = null;
                item.user_ans = null;
                await this.spinner.hide();

                this.service.ShowError('Please try again.');
              }
            } else {
              this.correct = 0;
              this.incorrct = 0;
              this.PracticeQuestionlist.forEach((element) => {
                if (element.answered == 1) {
                  this.correct = this.correct + 1;
                }
              });

              var answeredlength = this.PracticeQuestionlist.filter(
                (itemque) => itemque.answered == 0
              );
              if (answeredlength.length == 0) {
                this.viewresult();

                this.ViewResultbutton = true;
              } else {
                this.ViewResultbutton = false;
              }
              this.NextPracticeQuestionArray = [];
              if (
                this.PracticeQuestionlist.length - 1 >
                this.NextChnageQuestionNo
              ) {
                var arrayIndex = this.PracticeQuestionlist.findIndex(element => element.id == item.id);
                if (arrayIndex == this.NextChnageQuestionNo) {
                  this.NextChnageQuestionNo = this.NextChnageQuestionNo + 1;
                }
              }
              var answeredlength = this.PracticeQuestionlist.filter(
                (itemque) => itemque.answered == 0
              );
              if (answeredlength.length == 0) {
                this.viewresult();

                this.ViewResultbutton = true;
              } else {
                this.ViewResultbutton = false;
              }
              if (
                this.PracticeQuestionlist.length - 1 >=
                this.NextChnageQuestionNo
              ) {
                this.NextPracticeQuestionArray.push(
                  this.PracticeQuestionlist[this.NextChnageQuestionNo]
                );
              } else {
                if (answeredlength.length > 0) {
                  this.NextPracticeQuestionArray.push(
                    answeredlength[0]
                  );
                }
                else {
                  this.NextPracticeQuestionArray.push(
                    this.PracticeQuestionlist[
                    this.PracticeQuestionlist.length - 1
                    ]
                  );
                }
              }
              this.AnsValue = 0;
              this.IsCalcOpen = false;
            }
          }
        });
      await this.spinner.hide();
    } else {
      try {
        if (this.AnsValue != 0) {
          item.answered = 1;
          item.user_ans = this.AnsValue;
          this.isSaving = true
          await this.auth.getAuthenticatedUser().getSession(async (err, session) => {
            if (err) {
              this.router.navigate(['/login']);
            } else {
              if (this.PracticeQuestionlist.length > 0) {
                if (this.PracticeQuestionlist.length > this.AnswerComplter) {
                  this.AnswerComplter = this.AnswerComplter + 1;
                }
                this.correct = 0;
                this.PracticeQuestionlist.forEach((element, index) => {
                  if (element.answered == 1) {
                    this.correct = this.correct + 1;
                  }
                });
              }
              var token = session
              var correct = item.answer == this.AnsValue ? 1 : 0;

              if (!item.flag_review) {
                item.flag_review = 0;
              }
              var cohort_id = localStorage.getItem('cohort_id');
              var time = this.Hour + ':' + this.Minutes + ':' + this.Seconds;
              this.AnsValue = 0;
              this.NextPracticeQuestionArray = [];
              var arrayIndex = this.PracticeQuestionlist.findIndex(element => element.id == item.id);
              if (arrayIndex == this.NextChnageQuestionNo) {
                this.NextChnageQuestionNo = this.NextChnageQuestionNo + 1;
              }
              var answeredlength = this.PracticeQuestionlist.filter(
                (itemque) => itemque.answered == 0
              );
              if (answeredlength.length == 0) {
                this.viewresult();
                this.ViewResultbutton = true;
              } else {
                this.ViewResultbutton = false;
              }
              if (
                this.PracticeQuestionlist.length - 1 >=
                this.NextChnageQuestionNo
              ) {
                if (answeredlength.length > 0) {
                  this.NextPracticeQuestionArray.push(
                    answeredlength[0]
                  );
                }
                else {
                  this.NextPracticeQuestionArray.push(
                    this.PracticeQuestionlist[this.NextChnageQuestionNo]
                  );
                }
              } else {
                if (answeredlength.length > 0) {
                  this.NextPracticeQuestionArray.push(
                    answeredlength[0]
                  );
                }
                else {
                  this.NextPracticeQuestionArray.push(
                    this.PracticeQuestionlist[
                    this.PracticeQuestionlist.length - 1
                    ]
                  );
                }
              }
              await this.PracticeserviceService.addpracticetestans(
                this.userid,
                this.testid,
                item.id,
                item.user_ans,
                token,
                correct,
                item.d_id,
                item.sd_id,
                item.topic_id,
                item.flag_review,
                cohort_id,
                time
              ).then(async (data) => {
                this.isSaving = false
                if (data && data[0] && data[0].status == 200) {
                  var testdata = JSON.parse(<string>data[0].json);
                } else {
                  this.service.ShowError('Please try again.');
                  item.answered = null;
                  item.user_ans = null;
                  this.AnsValue = 0;
                }
              });
            }
          });
          await this.spinner.hide();
        }
        await this.spinner.hide();
      } catch {
        this.service.ShowError('Please try again.');
        item.answered = null;
        item.user_ans = null;
        this.AnsValue = 0;
        await this.spinner.hide();
      }
    }
    this.IsCalcOpen = false;
  }
  PreviousClick() {
    if (this.NextChnageQuestionNo != 0) {
      this.NextPracticeQuestionArray = [];
      this.NextChnageQuestionNo = this.NextChnageQuestionNo - 1;
      this.AnswerComplter = this.AnswerComplter - 1;
      if (this.PracticeQuestionlist.length - 1 >= this.NextChnageQuestionNo) {
        this.NextPracticeQuestionArray.push(
          this.PracticeQuestionlist[this.NextChnageQuestionNo]
        );
      } else {
        var data = btoa(JSON.stringify(this.testid));
      }
    }
    this.AnsValue = 0;
  }
  AnswerPreTest(ans, items) {
    if (this.examtype == 'ADAPTIVE') {
      if (ans != 0) {
        this.AnsValue = ans;
        items.user_ans = this.AnsValue;
      }
    } else {
      if (ans != 0) {
        this.AnsValue = ans;
        items.user_ans = this.AnsValue;
      }
    }
  }
  async viewresult() {
    await 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.PracticeserviceService.practicecomplate(
          this.userid,
          this.testid,
          token,
          cohort_id
        ).then((datas) => {
          var data = btoa(JSON.stringify(this.testid));
          this.service.testlogs_add(
            this.userid,
            this.testid,
            'PRACTICE',
            'END',
            token
          );
        });
      }
    });
  }
  calshow() {
    this.IsCalcOpen = !this.IsCalcOpen;
  }
  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.PracticeserviceService.IdPracticeTest(
              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 != ''
                ) {
                  this.Hour = list.data.time.split(':')[0];
                  this.Minutes = list.data.time.split(':')[1];
                  this.Seconds = 0;
                } else {
                  this.Hour = 1;
                  this.Minutes = 30;
                  this.Seconds = 0;
                }
              } else {
                await this.spinner.hide();
              }
              await this.examtimeset();
            });
          }
        });
    } catch (e) {
      await this.spinner.hide();

      this.service.ShowError(e.meassage);
    }
  }
  async ViewSet(items) {
    await 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.PracticeserviceService.practicecomplate(
          this.userid,
          this.testid,
          token,
          cohort_id
        ).then((datas) => {
          var data = btoa(JSON.stringify(this.testid));
          this.service.testlogs_add(
            this.userid,
            this.testid,
            'PRACTICE',
            'END',
            token
          );
        });
      }
    });
    let correct = this.PracticeQuestionlist.filter(x => x.user_ans == x.answer)
    let total = this.PracticeQuestionlist.length;

    var dataPass = {
      test_id: this.testid,
      RowNumber: 0,
      currect: correct.length,
      wrong: total - correct.length,
      currect_per: Math.round((correct.length * 100) / total),
      incurrect_per: 100 - Math.round((correct.length * 100) / total),
      total: total
    }
    var data = btoa(JSON.stringify(dataPass));
    data = encodeURIComponent(data);
    this.router.navigate([`sidenav/practicetestresult/${data}`]);
  }

  flagreviewclick() {
    this.Reviewpopup = true;
    this.ReviewArray = [];

    this.ShowflaggedSet = false;
    this.Showincomplete = false;
    this.bkparrayReviewArray = this.PracticeQuestionlist;
    var group = new Array();
    var j = 0;
    for (var i = 0; i < this.bkparrayReviewArray.length; i++) {
      if (i >= 5 && i % 5 === 0) {
        j++;
      }
      group[j] = group[j] || [];
      group[j].push(this.bkparrayReviewArray[i]);
    }

    this.ReviewArray = group;
  }
  closeSummary() {
    this.Reviewpopup = false;
  }
  Showflagged(item) {
    if (!this.ShowflaggedSet && !this.Showincomplete) {
      var ReviewArray = this.bkparrayReviewArray;
      var group = new Array();
      var j = 0;
      for (var i = 0; i < ReviewArray.length; i++) {
        if (i >= 5 && i % 5 === 0) {
          j++;
        }
        group[j] = group[j] || [];
        group[j].push(ReviewArray[i]);
      }
      this.ReviewArray = group;
    } else if (this.ShowflaggedSet && this.Showincomplete) {
      var ReviewArray = this.bkparrayReviewArray.filter(
        (item) => item.flag_review == 1 || item.answered == 1
      );
      var group = new Array();
      var j = 0;
      for (var i = 0; i < ReviewArray.length; i++) {
        if (i >= 5 && i % 5 === 0) {
          j++;
        }
        group[j] = group[j] || [];
        group[j].push(ReviewArray[i]);
      }
      this.ReviewArray = group;
    } else if (this.ShowflaggedSet && !this.Showincomplete) {
      var ReviewArray = this.bkparrayReviewArray.filter(
        (item) => item.flag_review == '1' && item.answered == 1
      );

      var group = new Array();
      var j = 0;
      for (var i = 0; i < ReviewArray.length; i++) {
        if (i >= 5 && i % 5 === 0) {
          j++;
        }
        group[j] = group[j] || [];
        group[j].push(ReviewArray[i]);
      }
      this.ReviewArray = group;
    } else if (!this.ShowflaggedSet && this.Showincomplete) {
      var ReviewArray = this.bkparrayReviewArray.filter(
        (item) => item.answered != 1
      );
      var group = new Array();
      var j = 0;
      for (var i = 0; i < ReviewArray.length; i++) {
        if (i >= 5 && i % 5 === 0) {
          j++;
        }
        group[j] = group[j] || [];
        group[j].push(ReviewArray[i]);
      }
      this.ReviewArray = group;
    } else {
      var ReviewArray = this.bkparrayReviewArray;
      var group = new Array();
      var j = 0;
      for (var i = 0; i < ReviewArray.length; i++) {
        if (i >= 5 && i % 5 === 0) {
          j++;
        }
        group[j] = group[j] || [];
        group[j].push(ReviewArray[i]);
      }
      this.ReviewArray = group;
    }
  }
  EndexamReview() {
    var datalength = this.PracticeQuestionlist.filter(
      (item) => item.answered == 0
    );
    if (datalength.length > 0) {
      this.EndExampopup = true;
    } else {
      var dataPass = {
        test_id: this.testid,
        RowNumber: 0
      }
      var data = btoa(JSON.stringify(dataPass));
      data = encodeURIComponent(data);
      this.router.navigate([`sidenav/practicetestresult/${data}`]);
    }
  }
  questionReview(item, i) {
    this.NextChnageQuestionNo = item.Srno - 1;
    this.NextPracticeQuestionArray = [];
    this.NextPracticeQuestionArray.push(
      this.PracticeQuestionlist[this.NextChnageQuestionNo]
    );
    this.Reviewpopup = false;
  }
  retuey() {
    window.location.reload();
  }
}
