import {Component, OnInit, ChangeDetectionStrategy, Output, EventEmitter, Input, OnChanges} from '@angular/core';
import {BaseList} from '../../../../../../../core/base/base-list';
import {
  ReceiptByPaymentCodeService
} from '../../../../../../../core/service/report/receipt-by-payment-code/receipt-by-payment-code.service';
import {SweetalertService} from '../../../../../../../core/service/sweetalert/sweetalert';

@Component({
  selector: 'app-list-payment-counter',
  templateUrl: './list-payment-counter.component.html',
  styleUrls: ['./list-payment-counter.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ListPaymentCounterComponent extends BaseList implements OnInit, OnChanges {
  @Output() reprint = new EventEmitter();
  @Output() OnCancelPay = new EventEmitter();
  @Input() paymentData: any = [];
  column = ['0', '1', '2', '3', '4', '5'];
  constructor(
    private reportPaymentcode: ReceiptByPaymentCodeService,
    private swSV: SweetalertService,
  ) {
    super();
  }

  ngOnInit(): void {
  }

  ngOnChanges(){
    console.log(this.paymentData)
    this.paymentData = this.updateMatTable(this.paymentData ? this.paymentData : []);
  }

  print(paymentCode, type: any){
    // console.log(paymentCode);
    if (paymentCode !== null){
      this.reportPaymentcode.getPdfReportReceiptForAll(paymentCode).subscribe(res => {
        const fileURL = URL.createObjectURL(res);
        window.open(fileURL, '_blank');
      });
    }else {
      this.swSV.error('กรุณากดรับเงินใหม่');
    }
  }

  printReal(paymentCode, type: any){
    // console.log(paymentCode);
    if (paymentCode !== null){
      this.reportPaymentcode.getPdfReportRealUat(paymentCode).subscribe(res => {
        const fileURL = URL.createObjectURL(res);
        window.open(fileURL, '_blank');
      });
    }else {
      this.swSV.error('กรุณากดรับเงินใหม่');
    }
  }

  cancelPay(registerUid){
    console.log(registerUid)
    this.OnCancelPay.emit(registerUid);
  }
}
