import { Component, OnInit, ChangeDetectionStrategy , Output, EventEmitter } from '@angular/core';
import {createQueryStringFromObject} from '../../../../shared/util/func';
import {AcademicYearService} from "../../../../core/service/settings/academic-year.service";
import {AcademicSemesterService} from "../../../../core/service/settings/academic-semester.service";


@Component({
  selector: 'app-manage-test-center-search',
  templateUrl: './manage-test-center-search.component.html',
  styleUrls: ['./manage-test-center-search.component.scss'],
  // changeDetection: ChangeDetectionStrategy.OnPush
})
export class ManageTestCenterSearchComponent implements OnInit {
  academicYearList;
  academicSemList;
  @Output() search = new EventEmitter();
  query = {
    academic_year_name_th: null,
    academic_semester_name_th: null,
    branch_name_th: null,
    testing_field_name_th: null,
    testing_room_name_th: null
  };

  constructor(
    private AcademicYearSV: AcademicYearService,
    private AcademicSemSV: AcademicSemesterService,
  ) { }

  ngOnInit(): void {
    this.AcademicYearSV.getAll().subscribe(
      result => {
        this.academicYearList = result;
      }
    );
    this.AcademicSemSV.getAll().subscribe(
      result => {
        this.academicSemList = result;
      }
    );
  }

  onSearch(){
    const query = createQueryStringFromObject(this.query);
    this.search.emit(query);
  }
  clear() {
    this.query = {
      academic_year_name_th: null,
      academic_semester_name_th: null,
      branch_name_th: null,
      testing_field_name_th: null,
      testing_room_name_th: null
    };
  }

}
