import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Observable } from 'rxjs';
import { ChangeTestingDateService } from 'src/app/core/service/testing-register/change-testing-date.service';
import { createQueryStringFromObject } from 'src/app/shared/util/func';

@Component({
  selector: 'app-change-exam-day',
  templateUrl: './change-exam-day.container.html',
  styleUrls: ['./change-exam-day.container.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ChangeExamDayContainer implements OnInit {
  emptyList$ = new Observable()
  waitList$ = new Observable()
  alrdyList$ = new Observable()
  curindex = 0;
  constructor(
    private changeSV: ChangeTestingDateService
  ) { }

  ngOnInit(): void {
    this.waitList$ = this.changeSV.search(`?seat_status_id=4`)
    this.alrdyList$ = this.changeSV.search(`?seat_status_id=2`)
    this.emptyList$ = this.changeSV.search(`?seat_status_id=3`)
  }

  index(index){
    this.curindex = index
    // console.log(this.curindex)
  }

  search(query){
    const data = createQueryStringFromObject(query)
    if(this.curindex == 0) return this.waitList$ = this.changeSV.search(`?${data}&seat_status_id=4`)
    if(this.curindex == 1) return this.alrdyList$ = this.changeSV.search(`?${data}&seat_status_id=2`)
    if(this.curindex == 2) return this.emptyList$ = this.changeSV.search(`?${data}&seat_status_id=3`)
  }

}
