import { GlobalPositionStrategy } from '@angular/cdk/overlay';
import { Component, OnInit } from '@angular/core';

import { InstructorService } from '../../../services/instructor.service';
import { CourseService } from '../../../services/course.service';

import { InstructorData } from '../../../structures/instructor-data';
import { CourseData } from '../../../structures/course-data';

import * as Globals from '../../../globals';
import * as CourseFilters from '../../../courseFilters';

@Component({
  selector: 'app-notification-pages',
  templateUrl: './notification-pages.component.html',
  styleUrls: ['./notification-pages.component.scss']
})
export class NotificationPagesComponent implements OnInit {

  title = Globals.pages.notifications.text;

  notApprovedInstructors: InstructorData[] | null = null;
  deniedInstructors: InstructorData[] | null = null;
  notApprovedCourses: CourseData[] | null = null;
  deniedCourses: CourseData[] | null = null;

  showDeniedInstructors: boolean = false;
  showDeniedCourses: boolean = false;

  constructor(private instructorService: InstructorService, private courseService: CourseService) { 
    this.instructorService.allInstructors$.subscribe((data: InstructorData[] | null) => {
      if(data != null) {
        this.notApprovedInstructors = data.filter( instructor => instructor.role == 'cekatel' );
        this.deniedInstructors = data.filter( instructor => instructor.role == 'blokovany' );
      }
    })
    this.instructorService.actualizeAllInstructors();  

    this.courseService.courses$.subscribe((data: CourseData[] | null) => {
      if(data != null) {
        this.notApprovedCourses = CourseFilters.filterRequestedCourses(data);
        this.deniedCourses = CourseFilters.filterDeniedCourses(data);
      }
    })
    this.notApprovedCourses = null;
    this.courseService.actualizeRequestedCourses(); 
  }

  ngOnInit(): void {
  }

}
