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

@Component({
    selector: 'app-approve-exam-search',
    templateUrl: './approve-exam-search.component.html',
    styleUrls: ['./approve-exam-search.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class ApproveExamSearchComponent implements OnInit {
    @Output() search = new EventEmitter();
    @Output() notification = new EventEmitter();
    academicYearList: any = [];
    academicSemList: any = [];
    query = {
        testing_information_name: null,
        academic_semester_code: null,
        academic_year_code: null
    };

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

    ngOnInit(): void {
        this.AcademicSemSV.getAll().subscribe(
            result => {
                this.academicSemList = result;
            }
        );
        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,
            academic_semester_code: null,
            academic_year_code: null
        };
    }

    noti() {
        this.notification.emit();
    }
}
