import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { Observable, throwError } from 'rxjs';
import { catchError, 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 { DailySummaryService } from 'src/app/core/service/testing-register/daily-summary.service';

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

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

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