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

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class SearchComponent implements OnInit {
  @Output() add = new EventEmitter();
  @Output() search = 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,
    registration_type: 1,
    is_open: true
  };
  constructor(
    private acdmYearSV: AcademicYearService,
  ) { }

  ngOnInit(): void {
    this.acdmYearSV.getAll().subscribe(
      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,
      registration_type: 1,
      is_open: true
    };
  }
}
