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

@Component({
  selector: 'app-manage-exam-officer-search',
  templateUrl: './manage-exam-officer-search.component.html',
  styleUrls: ['./manage-exam-officer-search.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ManageExamOfficerSearchComponent implements OnInit {
  @Output() add = new EventEmitter();
  @Output() search = new EventEmitter();
  academicYearList = [];

  query = {
    academic_year_code: null,
    testing_information_code: null,
    testing_information_name: null,
    academic_semester_code: null
  };
  constructor(
    private AcademicYearSV: AcademicYearService,
  ) { }

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

  onAdd(){
    this.add.emit();
  }

  onSearch(){
    let query = createQueryStringFromObject(this.query);
    this.search.emit(query);
  }

  clear(){
    this.query = {
      academic_year_code: null,
      testing_information_code: null,
      testing_information_name: null,
      academic_semester_code: null
    };
  }

}
