import {Component, OnInit, ChangeDetectionStrategy, OnChanges, ChangeDetectorRef, Input} from '@angular/core';
import {BaseList} from '../../../../../../core/base/base-list';
import {TestingRegisterService} from '../../../../../../core/service/testing-register/testing-register.service';
import {tap} from 'rxjs/operators';

@Component({
  selector: 'app-receive-payment-summary',
  templateUrl: './receive-payment-summary.component.html',
  styleUrls: ['./receive-payment-summary.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class ReceivePaymentSummaryComponent extends BaseList  implements OnInit , OnChanges{
  @Input() userData: any = [];
  @Input() registerList: any = [];
  listsummary;
  totalfee:number = 0 ;
  studentcount = 0;
  subjectcount = 0;
  constructor(
    private tesingregisterSV: TestingRegisterService,
    private cdr: ChangeDetectorRef
  ) {
    super();
  }

  ngOnInit(): void {
  }

  ngOnChanges(){
    console.log(this.registerList);
    if (this.registerList != null){
      this.studentcount = +this.registerList.length;
      for (let i = 0; i < this.registerList.length; i++) {
        const fee: number = +this.registerList[i].testing_fee;
        this.tesingregisterSV.get(this.registerList[i].testing_register_uid).pipe(
          tap(x => {
            const countSub: any = x;
            this.subjectcount += countSub.testing_subject_selecteds.length;
          }),
          tap(x => {
            this.cdr.detectChanges();
          }),
        ).subscribe(
        );
        this.totalfee += fee;
      }
      this.cdr.detectChanges();
    }
  }

}
