import {Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef} from '@angular/core';
import {TestingInformationService} from '../../../../../core/service/testing-information/testing-information.service';
import {Observable} from 'rxjs';
import {Router} from '@angular/router';
import {CustomeEventPage} from 'src/app/core/base/base-list';

@Component({
    selector: 'app-check-candidate-testing',
    templateUrl: './check-candidate-testing.container.html',
    styleUrls: ['./check-candidate-testing.container.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class CheckCandidateTestingContainer implements OnInit {
    testingInformation$ = new Observable();
    paginator;
    currentQueryPaging = '';
    currentQueryString = '';

    constructor(
        private testinforSV: TestingInformationService,
        private cdr: ChangeDetectorRef,
        private router: Router,
    ) {
    }

    ngOnInit(): void {
        this.search(`is_open=true`)
    }

    pageChange(event: CustomeEventPage) {
        this.paginator = event.paginator
        this.currentQueryPaging = event.queryStringPage
        if (this.currentQueryString) {
            return this.testingInformation$ = this.testinforSV.getPage(`${event.queryStringPage}?${this.currentQueryString}`)
        } else {
            return this.testingInformation$ = this.testinforSV.getPage(`${event.queryStringPage}`)
        }
    }

    search(queryString) {
        // if(query) return this.testingInformation$ = this.testinforSV.getSearchForCountSeat(`?${query}`);
        // if(!query) return this.testingInformation$ = this.testinforSV.getSearchForCountSeat(`?is_open=true`);
        this.currentQueryString = queryString
        if (queryString) {
            this.paginator.firstPage()
            return this.testingInformation$ = this.testinforSV.getPage(`${this.currentQueryPaging}?${this.currentQueryString}`)
        }
        if (!queryString) {
            return this.testingInformation$ = this.testinforSV.getPage(`${this.currentQueryPaging}?is_open=true`)
        }
    }

    view(id) {
        this.router.navigate(['check-candidate-list/view', id]);
    }

}
