import { ChangeDetectorRef, Component, ElementRef, OnInit, QueryList, ViewChildren } from '@angular/core';
import { StudyguideService } from '../../data/studyguide.service';
import { AuthserviceService } from '../../authservice.service';
import { NgxSpinnerService } from 'ngx-spinner';
import { ServicesService } from '../../services.service';
import { Router, ActivatedRoute } from '@angular/router';
import { DomSanitizer } from '@angular/platform-browser';
import { MatTabGroup } from '@angular/material/tabs';
import { SharedDataService } from 'src/app/services/SharedData/shared-data.service';

@Component({
  selector: 'app-review-guide',
  templateUrl: './review-guide.component.html',
  styleUrls: ['./review-guide.component.scss'],
})
export class ReviewGuideComponent implements OnInit {
  user_id: any;
  cohort_id: any;
  VideoPopup: boolean = false;
  MindmapPopup: boolean = false;
  PaymentAccess: boolean = false;
  IsAscending: boolean = true;
  PrioIsAscending: boolean = false;
  DomainExpand: boolean = true;
  PriorityExpand: boolean = true;
  studyguidedata = [];
  nofound = true;
  data: any;
  name: any;
  id: any;
  openMindMap: boolean = false;
  Questiondisplay = [];
  NextNumber = 0;
  previousnumber = 0;
  Questionsavedata = [];
  selecttab = 0;
  showtab = false;
  hepful = 1;
  feedback: any;
  SummaryActive: boolean = false;
  PDFActive: boolean = false;
  VideoActive: boolean = false;
  WrittenActive: boolean = false;
  PPTActive: boolean = false;
  ExcelActive: boolean = false;
  ImageActive: boolean = false;
  complete_ka = 0;
  complete_pt = 0;
  total_ka = 0;
  total_pt = 0;
  ttlcards = 0;
  ttlview = 0;
  complete_ka_per: any;
  complete_pt_per: any;
  complete_card_per: any;
  activeIndex: number;
  mobilepopup: boolean = false;

  showPpt: boolean = false;
  showDoc: boolean = false;
  showPdf: boolean = false;
  showXls: boolean = false;
  Pdfset: any;
  Pptset: any;
  Xlsset: any;
  selectedItem = '';

  showImg: boolean = false;
  Imgset: any;
  selectedImg = '';

  @ViewChildren('childTabs') childTabs: QueryList<MatTabGroup>;
  constructor(
    public studyguide: StudyguideService,
    public auth: AuthserviceService,
    public service: ServicesService,
    public spinner: NgxSpinnerService,
    public ActiveRoute: ActivatedRoute,
    public router: Router,
    public sanitizer: DomSanitizer,
    public cd: ChangeDetectorRef,
    public EleRef: ElementRef,
    public sharedDataService: SharedDataService
  ) {
    var setlogin = this.auth.isLoggedIn();
    if (!setlogin) {
      this.router.navigate(['/login']);
      this.spinner.hide();
    }
    this.service.headershow = true;
    this.service.SearchValue = true;
    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;
      }
    }
  }
  showBooks(Topic) {
    Topic.DropdownShow = !Topic.DropdownShow;
  }

  ngOnDestroy() {
    this.service.title = '';
  }
  async ngOnInit() {
    var data = window.localStorage.getItem('userdetails');
    this.user_id = localStorage.getItem('CisspUserId');
    this.cohort_id = localStorage.getItem('cohort_id');
    if (data != undefined || data != null || data != '') {
      this.data = JSON.parse(<string>data);
      this.name = this.data.aliasname ? this.data.aliasname : this.data.name;
      this.id = this.data.id;
      if (this.name != null) this.name = this.name.trim();
      this.service.name = this.name;
    }
    this.service.headerset = {
      dashboard: false,
      studyguuide: true,
      knowledge: false,
      knowques: false,
      knowresult: false,
      practice: false,
      cat: false,
      datestring: false,
      CATresult: false,
      CATQue: false,
      PracticeResult: false,
      Practiceques: false,
      studentprofile: false,
      resource: false,
      liveSupport: false
    };
    // await this.reviewguide();
    await this.userstudy();
    var sorting = localStorage.getItem('Cisspsorting') ? JSON.parse(localStorage.getItem('Cisspsorting')) : "";
    if (sorting != "") {
      if (sorting.name == "Priority") {
        this.PrioIsAscending = sorting.value;
        await this.PrioritySorting();
      }
      if (sorting.name == "DomainPriority") {
        this.IsAscending = sorting.value;
        await this.DomainSorting();
      }
    }
  }
  onpptopen(pptUrl, item, id, file_name){
    // this.showPpt = !this.showPpt;
    this.Pptset = pptUrl;
    this.showPpt = true;
    this.selectedItem = item;
    this.studyguide.UpdatePercentage(id, "PPT", this.cohort_id, this.user_id, file_name).then(async (data) => {
      if (data[0].status == 200) {
        var list = JSON.parse(<string>data[0].json);
        await this.sharedDataService.setSharedReviewGuideData([]);
        // await this.get_userstudy();
      }
    })
  }
  onDocopen(){
    this.showDoc = !this.showDoc;
  }
  onpdfopen(pdfUrl,  item, id, file_name){
    this.Pdfset = pdfUrl;
    this.showPdf = true;
    this.selectedItem = item;
    this.studyguide.UpdatePercentage(id, "PDF", this.cohort_id, this.user_id, file_name).then(async (data) => {
      if (data[0].status == 200) {
        var list = JSON.parse(<string>data[0].json);
        await this.sharedDataService.setSharedReviewGuideData([]);
        // await this.get_userstudy();
      }
    })
  }
  onImgOpen(imgUrl, item, id, file_name){
    this.Imgset = imgUrl;
    this.showImg = true;
    this.selectedImg = item;
    this.studyguide.UpdatePercentage(id, "IMAGE", this.cohort_id, this.user_id, file_name).then(async (data) => {
      if (data[0].status == 200) {
        var list = JSON.parse(<string>data[0].json);
        await this.sharedDataService.setSharedReviewGuideData([]);
        // await this.get_userstudy();
      }
    })
  }
  onExcelOpen(xlsUrl, item, id, file_name){
    this.Xlsset = xlsUrl;
    this.showXls = true;
    this.selectedItem = item;
    this.studyguide.UpdatePercentage(id, "EXCEL", this.cohort_id, this.user_id, file_name).then(async (data) => {
      if (data[0].status == 200) {
        var list = JSON.parse(<string>data[0].json);
        await this.sharedDataService.setSharedReviewGuideData([]);
        // await this.get_userstudy();
      }
    })
  }

  async DomainSorting() {
    if (!this.IsAscending) {
      this.studyguidedata = this.studyguidedata.sort((a, b) => (a.srno > b.srno) ? -1 : 1)
      this.DomainExpand = false;
    } else {
      this.studyguidedata = this.studyguidedata.sort((a, b) => (a.srno > b.srno) ? 1 : -1)
      this.DomainExpand = true;
    }
    localStorage.setItem('Cisspsorting', JSON.stringify({ "name": "Domain", "value": this.IsAscending }));
    this.IsAscending = !this.IsAscending
    this.PrioIsAscending = false;
    this.PriorityExpand = true;
  }

  async PrioritySorting() {
    if (!this.PrioIsAscending) {
      this.studyguidedata = this.studyguidedata.sort((a, b) => ((a.percent + a.wpercent) > (b.percent + b.wpercent)) ? -1 : 1)
      this.PriorityExpand = false;
    } else {
      this.studyguidedata = this.studyguidedata.sort((a, b) => ((a.percent + a.wpercent) > (b.percent + b.wpercent)) ? 1 : -1)
      this.PriorityExpand = true;
    }
    localStorage.setItem('Cisspsorting', JSON.stringify({ "name": "Priority", "value": this.PrioIsAscending }));
    this.DomainExpand = true;
    this.IsAscending = false;
    this.PrioIsAscending = !this.PrioIsAscending
  }

  MindMapClick(mind:any) {
    this.MindmapPopup = mind;
  }
  CloseMindmap() {
    this.openMindMap = false;
  }
  MindmappopupClose(event) {
    this.MindmapPopup = false;
  }
  async domainTab(item) {
    await this.studyguidedata.forEach((element) => {
      element.is_check = false;
      element.subdomains.forEach((el) => {
        el.is_check = false;
      });
    });
    item.is_check = !item.is_check;
  }
  async subDomainTab(item, sub) {
    await item.forEach((element) => {
      element.is_check = false;
    });
    sub.is_check = !sub.is_check;
    this.Questiondisplay = []
    this.NextNumber = 0;
    if (sub.PracticeQuestions && sub.PracticeQuestions.length > 0) {
      this.Questionsavedata = sub.PracticeQuestions;
      if (this.Questionsavedata.length > 0) {
        this.Questiondisplay.push(this.Questionsavedata[this.NextNumber]);
      }
    }
  }
  async userstudy() {
    let studyGuideList = this.sharedDataService.getSharedReviewGuideData()
    if (studyGuideList && studyGuideList.length > 0) {
      this.studyguidedata = studyGuideList
    } else {
      try {
        this.spinner.show();
        this.auth.getAuthenticatedUser().getSession(async (err, session) => {
          if (err) {
            this.spinner.hide();
            this.router.navigate(['/login']);
          } else {
            await this.spinner.show();
            var token = session
            var cid = localStorage.getItem('CisspCourseId');
            var cohort_id = localStorage.getItem('cohort_id');

            let method_id = localStorage.getItem('method');
            let method_type = localStorage.getItem('course_type');
            let user_id = localStorage.getItem('CisspUserId');
            let material_type = "Video";
            let study_progress = []
            // await this.studyguide.getReviewGuidePercentage(
            //   user_id,
            //   cid,
            //   cohort_id,
            //   token
            // ).then(async (data) => {
            //   if (data[0].status == 200) {
            //     var list = JSON.parse(<string>data[0].json);
            //     study_progress = list.data;
            //   }
            // })
            await this.studyguide.userstudyguidelist(this.id, cid, cohort_id, method_id, method_type, material_type, token).then(
              async (data) => {
                if (data[0].status == 200) {
                  var list = JSON.parse(<string>data[0].json);
                  if (list.data.length > 0) {
                    let selected_video = null
                    let selected_sub = null
                    let selected_mind = null
                    await list.data.forEach(async (d, i) => {
                      let dom_per = 0
                      let dom_per_inc = 0
                      let sub_dom_not_count = 0
                      d.subdomains.forEach((s, sDom_index) => {
                        let sub_dom_per = 0
                        let sub_dom_inper = 0
                        let topic_not_count = 0
                        s.topics.forEach((t, topicindex) => {
                          let count = 0;
                          // if (t.Flashcards.length > 0) {
                          //   count++
                          // }
                          // if(t.PracticeQuestions.length > 0){
                          //   count++;
                          // }
                          var studyProgressItem = study_progress.find(x => x.id === t.id);
                          // if(studyProgressItem.question_count > 0){
                          //   count++;
                          // }
                          // if(studyProgressItem.knowledge_count > 0){
                          //   count++;
                          // }
                          // t['flash_cor_per'] = studyProgressItem.flash_cor_per ? studyProgressItem.flash_cor_per : 0;
                          
                          // t['percent'] = ((studyProgressItem.flash_cor_per || 0) + (studyProgressItem.kpcorrectper || 0) + (studyProgressItem.pcorrectper || 0) + (studyProgressItem.practice_question_correct || 0)) / count;
                          // t['wpercent'] = ((studyProgressItem.pper || 0) + (studyProgressItem.flash_inc_per || 0) + (studyProgressItem.kper || 0) + ( studyProgressItem.practice_question_incorrect|| 0)) / count;
                          // if(t.Flashcards.length == 0 && t.PracticeQuestions.length == 0 && studyProgressItem.question_count == 0 && studyProgressItem.knowledge_count == 0){
                          //   t['percent'] = 100;
                          //   topic_not_count++
                          // }
                          // if(t.Flashcards.length == 0 && t.PracticeQuestions.length == 0 && studyProgressItem.question_count == 0 && studyProgressItem.knowledge_count == 0){
                          //   t['wpercent'] = 0;
                          // }
                          // if(t.Flashcards.length == 0 && t.PracticeQuestions.length == 0 && studyProgressItem.question_count == 0 && studyProgressItem.knowledge_count == 0 && s.topics.length == 1){
                          //   sub_dom_not_count++;
                          // }
                          // sub_dom_per += t['percent'];
                          // sub_dom_inper += t['wpercent'];

                          // t["showTab"] = false;
                          t.Video.forEach((videolistelement, video_index) => {
                            if (topicindex == 0 && video_index == 0 && selected_video == null) {
                              selected_video = videolistelement;
                              selected_sub = s.id;
                            }
                          });
                          // t.MindMaps.forEach((maps, map_index) => {
                          //   if (topicindex == 0 && map_index == 0 && selected_mind == null) {
                          //     selected_mind = maps;
                          //   }
                          // });

                          t['DropdownShow'] = false;
                          t['Bookdropdown'] = [];
                          t['Multipleshow'] = [];
                          if (t.ReferencesBook && t.ReferencesBook.length > 0) {
                            var groups = t.ReferencesBook.reduce(function (obj, item) {
                              obj[item.book_title] = obj[item.book_title] || [];
                              obj[item.book_title].push(item);
                              return obj;
                            }, {});

                            var myArray = Object.keys(groups).map(function (key) {
                              return { book_title: key, data: groups[key] };
                            });
                            if (myArray.length > 0) {
                              let newBookDropdwn = [];
                              if (myArray.length > 0) {
                                myArray.forEach(
                                  (newBook, i) => {
                                    newBookDropdwn.push(newBook);
                                  }
                                );
                              }
                              t['BookWiseRef'] = myArray;

                              t['Bookdropdown'] = newBookDropdwn;
                              if (t['Bookdropdown'].length > 0) {
                                t['Bookdropdown'].forEach(
                                  (Bookdropdowndata) => {
                                    Bookdropdowndata['checkmark'] = false;
                                  }
                                );
                              }
                            } else {
                              t['Bookdropdown'] = [];
                            }
                          } else {
                            t['Bookdropdown'] = [];
                          }
                          t.Summary.forEach((sum) => {
                            sum.content =
                              this.sanitizer.bypassSecurityTrustHtml(
                                sum.content
                              );
                              sum.pdf_files =sum.pdf_files ? JSON.parse(sum.pdf_files) : [];
                              sum.ppt_files =sum.ppt_files ? JSON.parse(sum.ppt_files) : [];
                              sum.image_files =sum.image_files ? JSON.parse(sum.image_files) : [];
                              sum.excel_files =sum.excel_files ? JSON.parse(sum.excel_files) : [];
                          });
                          this.PDFActive = true;
                        });
                        if(s.topics.length == 0){
                          sub_dom_not_count++;
                        }                        
                        // s.percent = s.topics.length <= 0 ? 100 : isNaN((sub_dom_per - (topic_not_count*100)) / (s.topics.length - topic_not_count)) ? 100 : (sub_dom_per - (topic_not_count*100)) / (s.topics.length - topic_not_count);
                        // s.wpercent = s.topics.length <= 0 ? 0 : isNaN(sub_dom_inper / (s.topics.length - topic_not_count)) ? 0 : sub_dom_inper / (s.topics.length - topic_not_count);
                        if (!s.percent) {
                          s.percent = 0;
                        }
                        if (!s.wpercent) {
                          s.wpercent = 0;
                        }       
                        // dom_per += s.topics.length <= 0 ? 100 : isNaN((sub_dom_per - (topic_not_count*100)) / (s.topics.length - topic_not_count)) ? 100 : (sub_dom_per - (topic_not_count*100)) / (s.topics.length - topic_not_count);
                        // dom_per_inc += s.topics.length <= 0 ? 0 : isNaN(sub_dom_inper / (s.topics.length - topic_not_count)) ? 0 : sub_dom_inper / (s.topics.length - topic_not_count);
                        sub_dom_per = 0;
                        sub_dom_inper = 0;
                        topic_not_count = 0;
                      });             
                      // d['percent'] = (dom_per - (sub_dom_not_count*100)) / (d.subdomains.length - sub_dom_not_count);
                      // d['wpercent'] = dom_per_inc / (d.subdomains.length - sub_dom_not_count);
                      d['srno'] = i + 1;
                      dom_per = 0
                      dom_per_inc = 0
                      sub_dom_not_count = 0
                      this.studyguidedata.push(d);
                    });
                    this.sharedDataService.setSharedReviewGuideData(this.studyguidedata)
                    // setTimeout(() => {
                      let is_video_mind = window.sessionStorage.getItem("is_video_mind")
                      if (is_video_mind == "video") {
                        this.Videoclick(selected_video, selected_sub)
                      }
                      if (is_video_mind == "mind") {
                        this.MindMapClick(selected_mind)
                      }
                      window.sessionStorage.removeItem("is_video_mind")
                    // }, 1000);
                    this.spinner.hide();
                  } else {
                    this.spinner.hide();
                  }
                } else {
                  this.spinner.hide();
                }
              },
              (err) => {
                this.spinner.hide();
              }
            );
            if (this.studyguidedata.length > 0) {
              this.nofound = true;
            } else {
              this.nofound = false;
            }
            // this.studyguidedata = this.studyguidedata.sort((a, b) => ((a.percent + a.wpercent) > (b.percent + b.wpercent)) ? 1 : -1)
          }
        });
      } catch (e) {
        await this.spinner.hide();
        this.service.ShowError(e.meassage);
      }
    }
    this.service.title = "<p class='HeaderUser'>" + this.name + "'s <span> Review Guide </span></p>";
  }
  async get_userstudy() {
    await this.spinner.show();
    var token = ''
    var cid = localStorage.getItem('CisspCourseId');
    var cohort_id = localStorage.getItem('cohort_id');

    let method_id = localStorage.getItem('method');
    let method_type = localStorage.getItem('course_type');
    let material_type = "Video";
    this.studyguidedata = [];
    await this.studyguide.userstudyguidelist(this.id, cid, cohort_id, method_id, method_type, material_type, token).then(
      async (data) => {
        if (data[0].status == 200) {
          var list = JSON.parse(<string>data[0].json);
          if (list.data.length > 0) {
            let selected_video = null
            let selected_sub = null
            let selected_mind = null
            await list.data.forEach(async (d, i) => {
              let sub_dom_not_count = 0
              d.subdomains.forEach((s, sDom_index) => {
                s.topics.forEach((t, topicindex) => {
                  t.Video.forEach((videolistelement, video_index) => {
                    if (topicindex == 0 && video_index == 0 && selected_video == null) {
                      selected_video = videolistelement;
                      selected_sub = s.id;
                    }
                  });

                  t['DropdownShow'] = false;
                  t.Summary.forEach((sum) => {
                    sum.content =
                      this.sanitizer.bypassSecurityTrustHtml(
                        sum.content
                      );
                      sum.pdf_files =sum.pdf_files ? JSON.parse(sum.pdf_files) : [];
                      sum.ppt_files =sum.ppt_files ? JSON.parse(sum.ppt_files) : [];
                      sum.image_files =sum.image_files ? JSON.parse(sum.image_files) : [];
                      sum.excel_files =sum.excel_files ? JSON.parse(sum.excel_files) : [];
                  });
                  this.PDFActive = true;
                });
                if(s.topics.length == 0){
                  sub_dom_not_count++;
                } 
                if (!s.percent) {
                  s.percent = 0;
                }
                if (!s.wpercent) {
                  s.wpercent = 0;
                }
              });             
              d['srno'] = i + 1;
              this.studyguidedata.push(d);
            });
            console.log('=================>updated data',this.studyguidedata);
            this.sharedDataService.setSharedReviewGuideData(this.studyguidedata)
              let is_video_mind = window.sessionStorage.getItem("is_video_mind")
              if (is_video_mind == "video") {
                this.Videoclick(selected_video, selected_sub)
              }
              if (is_video_mind == "mind") {
                this.MindMapClick(selected_mind)
              }
              window.sessionStorage.removeItem("is_video_mind")
            this.spinner.hide();
          } else {
            this.spinner.hide();
          }
        } else {
          this.spinner.hide();
        }
      },
      (err) => {
        this.spinner.hide();
      }
    );
    if (this.studyguidedata.length > 0) {
      this.nofound = true;
    } else {
      this.nofound = false;
    }
    // this.studyguidedata = this.studyguidedata.sort((a, b) => ((a.percent + a.wpercent) > (b.percent + b.wpercent)) ? 1 : -1)
    this.service.title = "<p class='HeaderUser'>" + this.name + "'s <span> Review Guide </span></p>";
  }
  checkboxchange(Topic, bookarray) {
    Topic.Multipleshow = bookarray.filter((item) => item.checkmark);
  }
  Videoclick(vid, subDomain_id) {
    vid["sd_id"] = subDomain_id;
    this.VideoPopup = vid;
    document.getElementsByTagName("body")[0].classList.add("popup-open")
  }
  popupClose(event) {
    this.VideoPopup = false;
    document.getElementsByTagName("body")[0].classList.remove("popup-open")
  }

  onTabChanged(item, data, index) {
    this.showPdf = false;
    this.selectedItem = '';

    this.activeIndex = index;
    this.childTabs.forEach(childTab => {
      childTab.realignInkBar();
    });
    if (data == "PDF") {
      this.PDFActive = true;
    } else {
      this.PDFActive = false;
    }
    if (data == "Video Lesson") {
      this.VideoActive = true;
    } else {
      this.VideoActive = false;
    }
    if (data == "Summary") {
      this.SummaryActive = true;
    } else {
      this.SummaryActive = false;
    }
    if (data == "PPT") {
      this.PPTActive = true;
    } else {
      this.PPTActive = false;
    }
    if (data == "Excel") {
      this.ExcelActive = true;
    } else {
      this.ExcelActive = false;
    }
    if (data == "Image") {
      this.ImageActive = true;
    } else {
      this.ImageActive = false;
    }
  }
  Topicclick(item) {
    item.showTab = true;
    this.NextNumber = 0;
    this.previousnumber = 0;
    this.mobilepopup = true;
  }
  tabchnageselect() {
    this.selecttab = 0;
    this.Questionsavedata = [];
    this.Questiondisplay = [];
  }
  Nextxlick() {
    if (this.Questionsavedata.length - 1 > this.NextNumber) {
      this.Questiondisplay = [];
      this.NextNumber += 1;
      this.Questiondisplay.push(this.Questionsavedata[this.NextNumber]);
    }
  }
  Previousclick() {
    if (this.NextNumber != 0) {
      this.Questiondisplay = [];
      this.NextNumber = this.NextNumber - 1;
      this.Questiondisplay.push(this.Questionsavedata[this.NextNumber]);

    }
  }
  feedbackCount(helpful) {
    this.hepful = helpful;
  }
  saveFeedback(items) {
    if (this.feedback == '' || this.feedback == null) {
      this.service.ShowError('Enter your feedback');
    } else {
      this.spinner.show();
      this.auth.getAuthenticatedUser().getSession(async (err, session) => {
        if (err) {
          await this.spinner.hide();
          this.router.navigate(['/login']);
        } else {
          var token = session
          let user_id = localStorage.getItem('CisspUserId');
          await this.studyguide
            .addStudyFeedback(
              user_id,
              items[0].id,
              this.hepful,
              this.feedback,
              token
            )
            .then(async (data) => {
              if (data[0].status == 200) {
                this.spinner.hide();
                this.service.ShowSuccess('Feedback Saved Successfully');
              } else {
                this.spinner.hide();
              }
            });
        }
      });
    }
  }
  retuey() {
    window.location.reload();
  }
  async reviewguide() {
    // this.spinner.show();
    this.auth.getAuthenticatedUser().getSession(async (err, session) => {
      if (err) {
        this.spinner.hide();
        this.router.navigate(['/login']);
      } else {
        var token = session
        var data = {
          user_id: localStorage.getItem('CisspUserId'),
          cohort_id: localStorage.getItem('cohort_id')
        }
        await this.studyguide.discussreviewguide(data, token)
          .then(async (data) => {
            if (data[0].status == 200) {
              // this.spinner.hide();
              var list = JSON.parse(<string>data[0].json);
              this.complete_ka = list.data.complete_ka ? list.data.complete_ka : 0;
              this.complete_pt = list.data.complete_pt ? list.data.complete_pt : 0;
              this.total_ka = list.data.total_ka;
              this.total_pt = list.data.total_pt;
              this.ttlcards = list.data.ttlcards;
              this.ttlview = list.data.ttlview;
              this.complete_ka_per = list.data.complete_ka ? Math.round(((this.complete_ka) * 100) / this.total_ka) + ' ' + (100 - Math.round(((this.complete_ka) * 100) / this.total_ka)) : "0 100";
              this.complete_pt_per = list.data.complete_pt ? Math.round(((this.complete_pt) * 100) / this.total_pt) + ' ' + (100 - Math.round(((this.complete_pt) * 100) / this.total_pt)) : "0 100";
              this.complete_card_per = Math.round(((this.ttlview) * 100) / this.ttlcards) + ' ' + (100 - Math.round(((this.ttlview) * 100) / this.ttlcards))
            }
          });
        // this.spinner.hide();
      }
    });
  }
  GotoResourcePage() {
    this.router.navigateByUrl('/sidenav/resource/#Apps');
  }
  async checkMobileQue(item, sub) {
    await item.forEach((element) => {
      element.is_check = false;
    });
    sub.is_check = false;
  }

}
