import {Component, OnInit, ChangeDetectionStrategy, Output, EventEmitter, Input} from '@angular/core';
import {createQueryStringFromObject} from '../../../../../shared/util/func';
import {SweetalertService} from '../../../../../core/service/sweetalert/sweetalert';

@Component({
  selector: 'app-report-summary-candidate',
  templateUrl: './report-summary-candidate.component.html',
  styleUrls: ['./report-summary-candidate.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ReportSummaryCandidateComponent implements OnInit {
  @Input() TestingInformationLists: any = [];
  @Input() AcademicYear = [];
  @Input() AcademicsemesterMock = [];
  @Output() search = new EventEmitter();
  @Output() excel = new EventEmitter();
  sectionsFake = [
    {
      "status_id": 1,
      "testing_center_period_uid": null,
      "period_id": 1,
      "is_check": false,
      "start_time": "09:00"
    },
    {
      "status_id": 1,
      "testing_center_period_uid": null,
      "period_id": 2,
      "is_check": false,
      "start_time": "12:00"
    },
    {
      "status_id": 1,
      "testing_center_period_uid": null,
      "period_id": 3,
      "is_check": false,
      "start_time": "15:00"
    },
    {
      "status_id": 1,
      "testing_center_period_uid": null,
      "period_id": 4,
      "is_check": false,
      "start_time": "18:00"
    }
  ];
  query = {
    academic_year_uid: null,
    academic_semester_uid: null,
    from_date: null,
    to_date: null,
  };
  constructor(
    private swSV: SweetalertService,
  ) { }

  ngOnInit(): void {
  }

  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 = {
      academic_year_uid: null,
      academic_semester_uid: null,
      from_date: null,
      to_date: null,
    };
  }

}
