import {Component, OnInit, ChangeDetectionStrategy, Input, Output, EventEmitter, ChangeDetectorRef} from '@angular/core';
import {SweetalertService} from '../../../../../core/service/sweetalert/sweetalert';
import {TestingInformationService} from '../../../../../core/service/testing-information/testing-information.service';

@Component({
  selector: 'app-report-exam-detail',
  templateUrl: './report-exam-detail.component.html',
  styleUrls: ['./report-exam-detail.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ReportExamDetailComponent implements OnInit {
  isUseTestCenterList = false;
  @Input() TestingInformationLists = [];
  @Output() search = new EventEmitter();
  @Output() excel = new EventEmitter();
  query = {
    testing_information_uid: null,
  };
  private curSub: any;
  private curSub2: any;
  constructor(
    private cdr: ChangeDetectorRef,
    private swSV: SweetalertService,
    private testingInforSV: TestingInformationService,
  ) { }

  ngOnInit(): void {
  }

  displayTestInfor(uid){
    if (uid && this.TestingInformationLists) return this.TestingInformationLists.find(x => x.testing_information_uid === uid)?.testing_information_name
    if (uid && !this.TestingInformationLists) return this.curSub?.testing_information_name
  }

  onSearch(){
    let checkNULL = false;
    checkNULL = this.checkFunction(this.query);
    if (checkNULL === false){
      this.search.emit(this.query);
    }
  }

  onExcel(){
    let checkNULL = false;
    checkNULL = this.checkFunction(this.query);
    if (checkNULL === false){
      this.excel.emit(this.query);
    }
  }

  checkFunction(object){
    for (const key in object) {
      if (!object[key]) {
        this.swSV.errText('กรุณาใส่ข้อมูลให้ครบถ้วน');
        return true;
      }
    }
    return false;
  }

  clear(){
    this.query = {
      testing_information_uid: null
    };
  }

}
