import {Component, Input, OnInit} from '@angular/core';
import {BrokerModel} from '../models/broker.model';
import {LoanModel} from '../models/loan.model';
import {LoanSummaryService} from '../service/loan_summary.service';
import {CompositeFilterDescriptor, SortDescriptor} from '@progress/kendo-data-query';
import {AuthService} from '../service/auth.service';
import {PeopleModel} from '../models/people.model';

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

  @Input() public broker: PeopleModel = PeopleModel.EmptyNew();
  public brokerLoans: LoanSummaryService;

  constructor( private lss: LoanSummaryService, private auth: AuthService) { }

  ngOnInit(): void {
    this.brokerLoans = this.lss;
    this.broker = this.auth.loggedIn.User;
    this.loadData();
  }

  private loadData(): void {
    const sort: Array <SortDescriptor> = [{dir:  'desc', field:  'Settlement'}];
    const filter: CompositeFilterDescriptor = {logic: 'and',  filters: []  };
    this.lss.query({ skip: 0, take: 1000, sort, filter});
  }

  private photoURL(peopleId: any): string {
    const url = this.auth.getUrl('avatar/') + peopleId;
    return 'url("' + url + '")';
  }
}
