import {Component, OnInit, ChangeDetectionStrategy, Input, OnChanges, ChangeDetectorRef} from '@angular/core';
import {BaseList} from '../../../../../core/base/base-list';
import {FormArray} from '@angular/forms';
import {SetExamInformationDialogComponent} from '../../dialog/set-exam-information-dialog/set-exam-information-dialog.component';
import {data} from 'autoprefixer';
import {MatDialog} from '@angular/material/dialog';
import {ActivatedRoute} from '@angular/router';
import {tap} from 'rxjs/operators';
import {TestingRoomService} from '../../../../../core/service/report/testing-room/testing-room.service';
import {SweetalertService} from '../../../../../core/service/sweetalert/sweetalert';

@Component({
  selector: 'app-setting-exam-view-table-center',
  templateUrl: './setting-exam-view-table-center.component.html',
  styleUrls: ['./setting-exam-view-table-center.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SettingExamViewTableCenterComponent extends BaseList implements OnInit, OnChanges {
  @Input() centerList: any = [];
  @Input() subjectList: any = [];
  column = ['1', '2', '3', '4', '5', '6', '7', '8'];

  constructor(
    private dialog: MatDialog,
    private cdRef: ChangeDetectorRef,
    private activeRouter: ActivatedRoute,
    private testingRoomSV: TestingRoomService,
    private swSV: SweetalertService,
  ) {
    super();
  }

  ngOnInit(): void {
  }

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

  openDialogexam(id:any,index:any){
    const centerList = this.centerList.data;
    const dialogRefedit = this.dialog.open(SetExamInformationDialogComponent, {
      width: '1000px',
      height: '700px',
      data: {
        id,
        centerList : centerList[index],
        subjectlist : this.subjectList,
        state : 'view',
      }
    });
  }

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

}
