import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';

@Component({
    selector: 'app-testing-info',
    templateUrl: './testing-info.container.html',
    styleUrls: ['./testing-info.container.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestingInfoContainer implements OnInit {
    testingInfo$ = new Observable()
    constructor(
        private testingInfomationSV: TestingInformationService,
    ) { }

    ngOnInit(): void {
        this.testingInfo$ = this.testingInfomationSV.searchForSeat(`?is_open=true`).pipe(
            map((x:any) => x.filter(a => a.type_of_examinee != 'บุคคลทั่วไป'))
        )
    }

    search(query){
        if(query) return this.testingInfo$ = this.testingInfomationSV.searchForSeat(`?is_open=true&${query}`).pipe(
            map((x:any) => x.filter(a => a.type_of_examinee != 'บุคคลทั่วไป'))
        );
        if(!query) return this.testingInfo$ = this.testingInfomationSV.searchForSeat(`?is_open=true&${query}`).pipe(
            map((x:any) => x.filter(a => a.type_of_examinee != 'บุคคลทั่วไป'))
        );
    }

}
