import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
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-testing-info',
  templateUrl: './testing-info.container.html',
  styleUrls: ['./testing-info.container.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestingInfoContainer implements OnInit {
  testingInfo$ = new Observable()
  query = {
    is_open: true,
    is_register: false,
    registration_type: 2,
    type_of_examinee: 'นักศึกษาโครงการพิเศษ/บุคคลทั่วไปแบบโครงการ'
  }
  querySting;
  constructor(
    private testingInfomationSV: TestingInformationService,
  ) {
    this.querySting = createQueryStringFromObject(this.query)
   }

  ngOnInit(): void {
    console.log(this.querySting)
    this.testingInfo$ = this.testingInfomationSV.searchForSeat(`?${this.querySting}`)
  }

  search(query){
    if(query) return this.testingInfo$ = this.testingInfomationSV.searchForSeat(`?${this.querySting}&${query}`);
    if(!query) return this.testingInfo$ = this.testingInfomationSV.searchForSeat(`?${this.querySting}&${query}`);
  }

}
