import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { SweetalertService } from 'src/app/core/service/sweetalert/sweetalert';
import { TestingInformationService } from 'src/app/core/service/testing-information/testing-information.service';
import { PeriodSummaryService } from 'src/app/core/service/testing-register/period-summary.service';

@Component({
  selector: 'app-period-summary',
  templateUrl: './period-summary.container.html',
  styleUrls: ['./period-summary.container.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class PeriodSummaryContainer implements OnInit {
  periodSummary$ = new Observable()
  testingInfo$ = new Observable()
  constructor(
    private periodSummarySV: PeriodSummaryService,
    private testingInfoSV: TestingInformationService,
    private swSV: SweetalertService
  ) { }

  ngOnInit(): void {
    this.testingInfo$ = this.testingInfoSV.getAll()
  }

  search(query){
    if(query) return this.periodSummary$ = this.periodSummarySV.searchSummary(query).pipe(
      tap((x:any) => {
        if(x.length == 0) this.swSV.errText('ไม่มีข้อมูล')
      })
    )
  }

}
