import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {concatMap, tap} from 'rxjs/operators';
import {ExamNotificationService} from '../../../../core/service/testing-information/exam-notification.service';
import {Observable} from 'rxjs';
import {SubjectsService} from '../../../../core/service/settings/subjects.service';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';

@Component({
  selector: 'app-notification-check-exam',
  templateUrl: './notification-check-exam.container.html',
  styleUrls: ['./notification-check-exam.container.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class NotificationCheckExamContainer implements OnInit {
  subjectList$ = new Observable();
  subjectListSend$ = [];
  testinForUid;
  testingInfoData
  constructor(
    private subjectSV: SubjectsService,
    private router: Router,
    private activeRouter: ActivatedRoute,
    private examNotiSV: ExamNotificationService,
    private testingInfoSV: TestingInformationService
  ) { }

  ngOnInit(): void {
    this.activeRouter.params.pipe(
      tap(x => {
        this.subjectList$ = this.examNotiSV.getByUid(x.id);
      }),
      concatMap(x => this.testingInfoSV.get(x.id)),
      tap(x => this.testingInfoData = x)
    ).subscribe();
    this.subjectSV.getAll().pipe(
      tap(x => {
        this.subjectListSend$ = x;
      }),
    ).subscribe();
  }

  search(query){
    if(query) return this.subjectList$ = this.examNotiSV.search(`?${query}`);
    if(!query) return this.subjectList$ = this.examNotiSV.getAll();
  }

}
