import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';
import { createQueryStringFromObject } from 'src/app/shared/util/func';

@Component({
    selector: 'app-exam-finance',
    templateUrl: './exam-finance.container.html',
    styleUrls: ['./exam-finance.container.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class ExamFinanceContainer implements OnInit {
    examFinanceList$ = new Observable();
    examFinanceListFalse$ = new Observable();
    index = 0
    constructor(
        private examFinanceSV: TestingInformationService, //later change
        private router: Router
    ) { }

    ngOnInit(): void {
        this.examFinanceList$ = this.examFinanceSV.getMaintrue();
        this.examFinanceListFalse$ = this.examFinanceSV.getMainfalse();
    }

    onIndex(index){
        this.index = index
    }

    search(query){
        if(this.index == 0){
            query.is_main = true
            let data = createQueryStringFromObject(query)
            if(data) return this.examFinanceList$ = this.examFinanceSV.search(`?${data}`);
        }
        if(this.index == 1){
            let data = createQueryStringFromObject(query)
            return this.examFinanceListFalse$ = this.examFinanceSV.searchFalse(`?${data}`);
        }
    }

    info(id){
        this.router.navigate(['setting-exam-finance/info/',id])
    }

}
