import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { concatMap, tap } from 'rxjs/operators';
import { BaseList } from 'src/app/core/base/base-list';
import { SweetalertService } from 'src/app/core/service/sweetalert/sweetalert';
import { GradingService } from 'src/app/core/service/testing-information/grading.service';

@Component({
  selector: 'app-grade-list',
  templateUrl: './grade-list.component.html',
  styleUrls: ['./grade-list.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class GradeListComponent extends BaseList implements OnInit {
  column = ['0', '1', '2', '3', '4', '5', '6','7'];
  gradeList: any = [];
  data;
  constructor(
    public activeRoute: ActivatedRoute,
    private cdr: ChangeDetectorRef,
    private router: Router,
    private gradingSV: GradingService,
    private swSV: SweetalertService
  ) {
    super()
   }

  ngOnInit(): void {
    this.activeRoute.paramMap.pipe(
      concatMap((x:any) => this.gradingSV.search('?subject_uid='+x.params.id+'&testing_information_uid='+x.params.uid)),
      tap(x => this.data = x[0]),
      tap(x => this.gradeList = this.updateMatTable(x))
    ).subscribe()
  }

  onView(id){
    this.router.navigate(['grade-summary/view',id])
  }

}
