import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AcademicYearService } from 'src/app/core/service/settings/academic-year.service';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';

@Component({
  selector: 'app-testing-info',
  templateUrl: './testing-info.container.html',
  styleUrls: ['./testing-info.container.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestingInfoContainer implements OnInit {
  academicYear$ = new Observable()
  testingInfo$ = new Observable()
  constructor(
    private testingInfoSV: TestingInformationService,
    private academicYearSV: AcademicYearService,
    private router: Router
  ) { }

  ngOnInit(): void {
    this.testingInfo$ = this.testingInfoSV.search(`?is_open=true`);
    this.academicYear$ = this.academicYearSV.getAll()
  }

  view(id){
    this.router.navigate(['candidate-payment-status/view', id]);
  }

  search(query){
    if(query) return this.testingInfo$ = this.testingInfoSV.search(`?${query}`);
    if(!query) return this.testingInfo$ = this.testingInfoSV.search(`?is_open=true`);
  }

}
