import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ServicesService } from 'src/app/services.service';

@Component({
  selector: 'app-resource',
  templateUrl: './resource.component.html',
  styleUrls: ['./resource.component.scss'],
})

export class ResourceComponent implements OnInit {
  private fragment: string;
  VideoPopup: boolean = false;
  MindmapPopup: boolean = false;
  constructor(public service: ServicesService, public router: Router, private route: ActivatedRoute) {
    this.service.headershow = true;
    this.service.SearchValue = true;
  }

  ngOnInit(): void {
    this.service.headerset = {
      dashboard: false,
      studyguuide: false,
      knowledge: false,
      practice: false,
      cat: false,
      datestring: false,
      CATresult: false,
      CATQue: false,
      PracticeResult: false,
      Practiceques: false,
      studentprofile: false,
      knowques: false,
      knowresult: false,
      resource: true,
      liveSupport: false
    };
    this.route.fragment.subscribe(fragment => { this.fragment = fragment; });
    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;
      }
    }
  }
  ngAfterViewInit(): void {
    try {
      document.querySelector('#' + this.fragment).scrollIntoView();
    } catch (e) { }
  }
  Videoclick(vid) {
    vid = {
      "id": 8,
      "video_title": "Ethics",
      "video_thumbnil": "https://d1a3hgjjjt035i.cloudfront.net/43.png",
      "duration": "08:06",
      "type": "FREE",
      "video_link": "https://d2lvcf3eiz2es3.cloudfront.net/43.mp4",
      "sd_id": 104
    }
    this.VideoPopup = vid;
  }
  MindMapClick(mind) {
    mind = {
    "id": 29,
    "thumbnail_link": "https://d34uhbkdfs5fh7.cloudfront.net/2.2+YT-thumbnail.png",
    "name": "Privacy"
    }
    this.MindmapPopup = mind;
  }

  popupClose(event) {
    this.VideoPopup = false;
  }
  MindmappopupClose(event) {
    this.MindmapPopup = false;
  }
  redirect(item) {
    if (item == 'dashboard') {
      this.router.navigate([`/sidenav/dashboard`]);
    }
    if (item == 'study') {
      this.router.navigate([`/sidenav/study`]);
    }
    if (item == 'schedule') {
      this.router.navigate([`/sidenav/schedule`]);
    }
    if (item == 'knowledge') {
      this.router.navigate([`/sidenav/knowledge`]);
    }
    if (item == 'practicetest') {
      this.router.navigate([`/sidenav/practicetest`]);
    }
    if (item == 'chatting') {
      this.router.navigate([`/sidenav/chatting`]);
    }
    if (item == 'Videoleasson') {
      window.sessionStorage.setItem("is_video_mind", "video")
      this.router.navigate([`/sidenav/study`]);
    }
    if (item == 'mind_map') {
      window.sessionStorage.setItem("is_video_mind", "mind")
      this.router.navigate([`/sidenav/study`]);
    }
  }
  Appfile(item) {
    if (item == 'Android') {
      window.open(
        'https://play.google.com/store/apps/details?id=com.cissp.destinationcertification'
      );
    } else {
      window.open(
        'https://apps.apple.com/in/app/destination-cissp-flashcards/id1445430932'
      );
    }
  }
  retuey() {
    window.location.reload();
  }
}
