import {Component, Input, OnInit} from '@angular/core';
import {LoanSummaryService} from '../service/loan_summary.service';
import {CompositeFilterDescriptor, SortDescriptor} from '@progress/kendo-data-query';
import {PeopleModel} from '../models/people.model';
import {AppConfig} from '../app.config';
import {SessionService} from '../service/session.service';

@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 ss: SessionService, private config: AppConfig) { }

  ngOnInit(): void {
    this.brokerLoans = this.lss;
    this.broker = this.ss.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.config.getUrl('avatar/') + peopleId;
    return 'url("' + url + '")';
  }
}
