import {Component, OnInit, ChangeDetectionStrategy, Input, OnChanges} from '@angular/core';
import {BaseList} from '../../../../../core/base/base-list';
import {tap} from 'rxjs/operators';
import {ActivatedRoute} from '@angular/router';
import {TestingRoomService} from '../../../../../core/service/report/testing-room/testing-room.service';
import {SweetalertService} from '../../../../../core/service/sweetalert/sweetalert';
import {TesingSubjectService} from '../../../../../core/service/report/testing-subject/tesing-subject.service';

@Component({
  selector: 'app-setting-exam-view-table-subject',
  templateUrl: './setting-exam-view-table-subject.component.html',
  styleUrls: ['./setting-exam-view-table-subject.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SettingExamViewTableSubjectComponent extends BaseList implements OnInit, OnChanges {
  @Input() subjectList: any = [];
  column = ['1', '2', '3'];
  constructor(
    private activeRouter: ActivatedRoute,
    private testingSubjectSV: TesingSubjectService,
    private swSV: SweetalertService,
  ) {
    super();
  }

  ngOnInit(): void {
  }

  ngOnChanges(){
    this.subjectList = this.updateMatTable(this.subjectList ? this.subjectList : []);
  }

  onExcel(){
    this.activeRouter.params.pipe(
      tap((y: any) => {
        console.log(y.id);
        this.testingSubjectSV.getExcelReport(
          y.id,
        ).subscribe(
          res => {
            // window.open(fileURL, '_blank');
          },
          error => {
            this.swSV.errText('ไม่พบข้อมูล')
          });
      })
    ).subscribe();
  }

}
