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

@Component({
  selector: 'random-questions-search',
  templateUrl: './random-questions-search.component.html',
  styleUrls: ['./random-questions-search.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class RandomQuestionsSearchComponent implements OnInit {
  academicYearList = [];
  @Output() search = new EventEmitter()
  query={
    testing_information_name:null,
    testing_information_code:null,
    academic_semester_code:null,
    academic_year_code:null
  }
  constructor(
    private AcademicYearSV: AcademicYearService,
  ) { }

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

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

  clear(){
    this.query = {
      testing_information_name:null,
      testing_information_code:null,
      academic_semester_code:null,
      academic_year_code:null
    }
    const query = createQueryStringFromObject(this.query)
    this.search.emit(query)
  }

}
