import { Component, OnInit, ChangeDetectionStrategy, Inject, ChangeDetectorRef } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { tap } from 'rxjs/operators';
import { BranchService } from 'src/app/core/service/settings/branch.service';
import { TestingFieldService } from 'src/app/core/service/settings/testing-field.service';

@Component({
  selector: 'app-preview',
  templateUrl: './preview.component.html',
  styleUrls: ['./preview.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class PreviewComponent implements OnInit {
  testingFieldList: any = [];
  branchList: any = [];
  constructor(
    public dialogRef: MatDialogRef<PreviewComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
    private branchSV: BranchService,
    private testingFieldSV: TestingFieldService,
    private cdr: ChangeDetectorRef
  ) { }

  ngOnInit(): void {
    this.testingFieldSV.getAll().pipe(
      tap(x => this.testingFieldList = x),
      tap(x => this.cdr.detectChanges())
    ).subscribe()
    this.branchSV.getAll().pipe(
      tap(x => this.branchList = x),
      tap(x => this.cdr.detectChanges())
    ).subscribe()
  }

  print(){
    window.print()
  }

}
