import { Component, OnInit } from '@angular/core';
import {UploadMetaModel} from '../models/uploadMetaModel';
import {UploadAttachService} from '../service/upload.attach.service';
import {LoanModel} from '../models/loan.model';
import {LoanSingleService} from '../service/loan.single.service';

@Component({
  selector: 'app-list-income',
  templateUrl: './list-income.component.html',
  styleUrls: ['./list-income.component.scss']
})
export class ListIncomeComponent implements OnInit {
  public uploadMeta: UploadMetaModel = new UploadMetaModel({});
  public Loan: LoanModel = new LoanModel({});
  public startLoad = false;

  private UploadMetaFilterIsReady = false;
  private LoanFilterIsReady = false;
  constructor(private uas: UploadAttachService, private lss: LoanSingleService) { }

  ngOnInit(): void {
      this.UploadMetaFilterIsReady = true;

      // this.UploadMetaFilterIsReady = false;
      // this.uas.getUploadMeta(1).subscribe(
      //   resp => {
      //     this.UploadMetaFilterIsReady = true;
      //     this.checkStartUpload();
      //     // this.uploadMeta = new UploadMetaModel(resp);
      //   }, error => {
      //     this.UploadMetaFilterIsReady = true;
      //     this.checkStartUpload();
      //   }, () => {
      //     this.UploadMetaFilterIsReady = true;
      //     this.checkStartUpload();
      //   }
      // );

      // this.lss.getLoan('0482b524-d396-4b03-8abb-f8325c87e2ed').subscribe(
      //   resp => {
      //     this.Loan = new LoanModel(resp);
      //     this.LoanFilterIsReady = true;
      //     this.checkStartUpload();
      //   }, err => {
      //     this.LoanFilterIsReady = true;
      //     this.checkStartUpload();
      //   }, () => {
      //     this.LoanFilterIsReady = true;
      //     this.checkStartUpload();
      //   }
      // );
      this.startLoad = true;
  }

  private checkStartUpload(): void {
     this.startLoad = this.UploadMetaFilterIsReady && this.LoanFilterIsReady;
  }
}
