import { Component, OnInit } from '@angular/core';
import {LoanModel} from '../models/loan.model';
import {LoanSingleService} from '../service/loan.single.service';
import {AuthService} from '../service/auth.service';

@Component({
  selector: 'app-client-loan-list',
  templateUrl: './client-loan-list.component.html',
  styleUrls: ['./client-loan-list.component.scss']
})
export class ClientLoanListComponent implements OnInit {

  public Loans: LoanModel[] =[];

  constructor(private ls: LoanSingleService, private auth: AuthService) { }

  ngOnInit(): void {
    this.ls.getLoanByClient(this.auth.loggedIn.User.Id).subscribe(
      resp => {
        this.Loans = [];
        resp.forEach( v => {
           const l = new LoanModel(v);
           l.Response = v;
           this.Loans.push(l);
        });
      }
    );
  }

  public goodDate(d: Date): boolean {
    const n = new Date();
    return d.getFullYear() + 10 > n.getFullYear(); // shouldn't be 10 years old.
  }
}
