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

@Component({
  selector: 'app-list-enrollment-counter-payment',
  templateUrl: './list-enrollment-counter-payment.component.html',
  styleUrls: ['./list-enrollment-counter-payment.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ListEnrollmentCounterPaymentComponent extends BaseList implements OnInit, OnChanges {
  @Output() pay = new EventEmitter();

  @Input() enrollmentData: any = [];
  column = ['0', '1', '2', '3'];

  constructor(
    private reportPaymentcode: ReceiptByPaymentCodeService,
  ) {
    super();
  }

  ngOnInit(): void {
  }

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

  onPay(testRegisterUid){
    this.pay.emit(testRegisterUid);
  }

  onPrint(paymentCode){
    // const paymentcode = paymentCode.replace(/^..../g, '');
    this.reportPaymentcode.getPdfReportReceiptForAll(paymentCode).subscribe(res => {
      const fileURL = URL.createObjectURL(res);
      window.open(fileURL, '_blank');
    });
  }

}
