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

@Component({
  selector: 'app-create-exam-subject-search',
  templateUrl: './create-exam-subject-search.component.html',
  styleUrls: ['./create-exam-subject-search.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class CreateExamSubjectSearchComponent implements OnInit {

  @Output() search = new EventEmitter();
  @Output() add = new EventEmitter();
  academicYearList;
  statusMock = [{id: 1, name: 'ใช้งาน'}, {id: 2, name: 'ยกเลิก'}];
  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;
      }
    );
  }

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

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

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

}
