import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import {Observable} from 'rxjs';
import {DailySummaryService} from '../../../../../core/service/testing-register/daily-summary.service';
import {TestingInformationService} from '../../../../../core/service/testing-information/testing-information.service';
import {SweetalertService} from '../../../../../core/service/sweetalert/sweetalert';
import {tap} from 'rxjs/operators';
import {DailySummaryTtbService} from '../../../../../core/service/testing-register/daily-summary-ttb.service';

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

  ngOnInit(): void {
    this.testingInfo$ = this.testingInfoSV.getAll()
    this.dailySummary$ = this.dailySummaryTtbSV.getAll()
    // this.dailySummary$ = this.dailySummaryTtbSV.getAll().pipe(
    //   tap(x => {
    //     console.log(x);
    //     const data:any = x;
    //     console.log(data.response.data[0])
    //     this.dailySummary$ = data.response.data[0];
    //   })
    // ).subscribe();
  }

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

}
