import { Component, OnInit, ChangeDetectionStrategy, Inject, ChangeDetectorRef } from '@angular/core';
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { tap } from 'rxjs/operators';
import { SweetalertService } from 'src/app/core/service/sweetalert/sweetalert';
import { GradingService } from 'src/app/core/service/testing-information/grading.service';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';

@Component({
  selector: 'app-grade-dialog',
  templateUrl: './grade-dialog.component.html',
  styleUrls: ['./grade-dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class GradeDialogComponent implements OnInit {
  testingList: any = [];
  gradeData;
  constructor(
    public dialog: MatDialog,
    public dialogRef: MatDialogRef<GradeDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
    private swSV: SweetalertService,
    private gradingSV: GradingService,
    private cdr: ChangeDetectorRef
  ) { }

  ngOnInit(): void {
    // console.log(this.data)
    this.gradingSV.search(`?subject_uid=${this.data}`).pipe(
      tap(x => this.testingList = x),
      tap(x => this.cdr.detectChanges())
    ).subscribe()
  }

  confirm(){
    this.gradingSV.get(this.gradeData).pipe(
      tap(x => this.dialogRef.close({grade_data: x}))
    ).subscribe()
  }

  cancel(){
    this.dialogRef.close()
  }


}
