<title>Business Loan</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Business Loan'" [active_item]="'Business Loan'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">

          <button *ngIf="businessLoans && businessLoans.length > 0" type="button" class="btn btn-info filterbtn"
            title="{{ 'tooltip_lbl_download_csv' |translate}}" (click)="downloadCsv()">
            <i class="icon-download pr-1"></i>
            <span>{{'lbl_downLoad_csv'| translate}}</span>
          </button>
          <button type="button" class="btn btn-info filterbtn" title="{{ 'tooltip_lbl_filter_loans' |translate}}"
            (click)="drawer.toggle();">
            <i class="icon-filter pr-1"></i>
            <span>{{'button_lbl_filter'| translate}}</span>
          </button>
        </div>
      </div>
    </div>
    <div class="col-sm-12">
      <mat-drawer-container autosize>
        <div class="card">
          <ng-container *ngIf="businessLoans && isFlag else NoBusinessLoans">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="businessLoans"
                class="mat-elevation-z8 table-striped table-vcenter lastcolumntable"
                style="min-width: 2000px; box-shadow: none;" aria-label="businessLoan">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef style="width:5%">#</th>
                  <td mat-cell *matCellDef="let element; let i = index;" style="width:5%px">
                    {{(paginate.currentPage - 1) * paginate.pageSize + i + 1}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="Customer">
                  <th mat-header-cell *matHeaderCellDef style="width:15%">{{'lbl_customer'| translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width:15%">
                    <a (click)="navigateCustomerDetail(element)">{{element.basicDetail?.fullName}}</a>
                  </td>
                </ng-container>
                <ng-container matColumnDef="ContactNo">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_contact_no'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.basicDetail.contactNo else Novalue">
                      {{element?.basicDetail?.contactNo}}
                    </ng-container>
                    <ng-template #Novalue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Email">
                  <th mat-header-cell *matHeaderCellDef style="width:15%">{{'lbl_email'| translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width:15%">
                    <ng-container *ngIf="element.basicDetail.email else Novalue">
                      {{element?.basicDetail?.email}}
                    </ng-container>
                    <ng-template #Novalue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="LoanAmount">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_loan_amount'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.basicDetail?.loanAmount else NoValue">
                      {{currency}}{{element.basicDetail?.loanAmount | number:'0.2-2'}}
                    </ng-container>
                    <ng-template #NoValue>
                      {{currency}}<span class="text-center">0</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Employment">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_employment'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.basicDetail.employmentType else Novalue">
                      {{element.basicDetail?.employmentType}}
                    </ng-container>
                    <ng-template #Novalue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Status">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_status'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.basicDetail && element.basicDetail.status else NoValue">
                      <span
                        *ngIf="(element.basicDetail && element.basicDetail.status == 'PENDING' || element.basicDetail.status == 'REJECTED' ) else NoPending"
                        style="color: #ff0000;">
                        {{element.basicDetail?.status}}
                      </span>
                      <ng-template #NoPending>
                        <span style="color: #0b9d0b;">{{element.basicDetail?.status}}</span>
                      </ng-template>
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center" style="color: #ff0000;">{{'lbl_pending'| translate}}</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="DSACode">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_file_source'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container>
                      <span
                        *ngIf="element.basicDetail.partnerId && !element.basicDetail.leadId">{{'lbl_channel_partner'|
                        translate}}</span>
                      <span *ngIf="!element.basicDetail.partnerId && !element.basicDetail.leadId">{{'lbl_direct'|
                        translate}}</span>
                      <span *ngIf="element.basicDetail.leadId">{{'lbl_from_lead'| translate}}</span>
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="rmFullName">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_assigned_rm'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.basicDetail.rmFullName else Novalue">
                      {{element?.basicDetail?.rmFullName}}
                    </ng-container>
                    <ng-template #Novalue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="createdDate">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_request_date'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    {{element.basicDetail.createdDate | date:'medium'}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="isDelete">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_delete'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <span *ngIf="element?.basicDetail?.isDelete == '1' else NoDelete" style="color: #ff0000;">
                      {{'lbl_yes'| translate}}
                    </span>
                    <ng-template #NoDelete>
                      <span style="color: #0b9d0b;">{{'lbl_no'| translate}}</span>
                    </ng-template>
                  </td>
                </ng-container>

                <ng-container matColumnDef="Action" stickyEnd>
                  <th mat-header-cell *matHeaderCellDef class="text-right">
                    {{'lbl_action'| translate}}</th>
                  <td mat-cell *matCellDef="let element" class="text-right">
                    <button mat-button [matMenuTriggerFor]="menu" (click)="toggleMenuService.toggleMenuStyles()"> <a
                        href="javascript:;" class="btn btn-sm btn-info filterbtn"
                        title="{{ 'tooltip_lbl_action' |translate}}">
                        <i class="fa fa-angle-down"></i>
                      </a></button>
                    <mat-menu #menu="matMenu">
                      <div mat-menu-item class="p-0 mx-2" (click)="navigateEditLoanPage(element)"
                        *ngIf="isEditPermission && !element.basicDetail.isDelete ">
                        <a title="{{ 'tooltip_lbl_edit_loan' |translate}}" href="javascript:;"
                          class="btn btn-sm btn-info filterbtn">
                          <i class="icon-pencil"></i>
                        </a>{{'lbl_edit'| translate}}
                      </div>
                      <div mat-menu-item class="p-0 mx-2" (click)="viewDetail(element)" *ngIf="isReadPermission ">
                        <a title="{{ 'tooltip_lbl_view_detail' |translate}}" href="javascript:;"
                          class="btn btn-sm btn-info filterbtn">
                          <i class="icon-eye"></i>
                        </a>{{'lbl_view_detail'| translate}}
                      </div>

                      <div mat-menu-item class="p-0 mx-2" (click)="warningAlert(element)"
                        *ngIf="element.basicDetail?.status && isDeletePermission && !element.basicDetail.isDelete && element.basicDetail?.status != 'REJECTED'">
                        <a title="{{ 'business_loan_tooltip_lbl_delete_business_loan' |translate}}" href="javascript:;"
                          class="btn btn-sm btn-info filterbtn">
                          <i class="fa fa-trash"></i>
                        </a>{{'lbl_delete'| translate}}
                      </div>
                    </mat-menu>
                  </td>
                </ng-container>
                <tr mat-header-row *matHeaderRowDef="displayColumns; sticky: true"></tr>
                <tr mat-row *matRowDef="let row; columns: displayColumns;" class="student-element-row"
                  style="cursor: pointer;"></tr>
              </table>
            </div>
          </ng-container>
          <ng-template #NoBusinessLoans>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>

          <div class="card-footer" *ngIf="businessLoans && businessLoans.length > 0">
            <ul class="pagination mb-0 float-right">
              <li [ngClass]="{ disabled: paginate.currentPage == 1 }" class="page-item page-prev">
                <a class="page-link" href="javascript:;" tabindex="-1" (click)="setPage(paginate.currentPage - 1)">
                  <span>{{'button_lbl_prev'| translate}}</span>
                </a>
              </li>
              <li *ngFor="let page of paginate.pages" class="page-item active"
                [ngClass]="{ active: paginate.currentPage == page }"><a
                  [ngClass]="{current:paginate.currentPage == page}" class="page-link" href="javascript:;"
                  (click)="setPage(page)">{{page}}</a></li>
              <li [ngClass]="{ disabled: paginate.currentPage === paginate.totalPages}"
                (click)="setPage(paginate.currentPage + 1)" class="page-item page-next">
                <a class="page-link" href="javascript:;"><span>{{'button_lbl_next'| translate}}</span></a>
              </li>
            </ul>
          </div>

        </div>

        <mat-drawer #drawer class="example-sidenav" mode="over" position="end">
          <div class="col-lg-12 px-3 pt-3">
            <div class="d-inline" style="width: 100%;"><i class="fa fa-filter pr-1"><span
                  class="ml-1">{{'button_lbl_filter'|
                  translate}}</span></i>
              <button v class="close" aria-label="Close" (click)="drawer.toggle();">
                <span aria-hidden="true">&times;</span>
              </button>
            </div>
          </div>
          <hr>
          <div class="position px-3">
            <div class="form-group">
              <label>{{'lbl_search'| translate}}</label>
              <input type="text" class="form-control" placeholder="searchBy Name,ContactNo" [(ngModel)]="searchString">
            </div>
            <div class="form-group">
              <label>{{'lbl_select_statusStatus'| translate}}</label>
              <ng-select [items]="loanStatuses" class="js-example-basic-single p-0"
                placeholder="{{ 'placeholder_lbl_search_by_status' |translate}}" bindLabel="status" bindValue="id"
                name="selectedStatus" [(ngModel)]="selectedStatus">
              </ng-select>
            </div>
            <div>
              <div class="col-form-label">{{'lbl_from_date'| translate}}</div>
              <mat-form-field appearance="outline" class="d-block w-100"
                (click)="toggleMenuService.togglePickerStyles()">
                <input matInput [matDatepicker]="filterPickerFrom" [max]="dateTo"
                  placeholder="{{ 'lbl_from_date' |translate}}" [(ngModel)]="dateFrom" name="fromDate" [readonly]="true"
                  (focus)="filterPickerFrom.open()" (click)="toggleMenuService.togglePickerStyles()">
                <mat-datepicker-toggle matSuffix [for]="filterPickerFrom"
                  (click)="toggleMenuService.togglePickerStyles()">
                </mat-datepicker-toggle>
                <mat-datepicker #filterPickerFrom></mat-datepicker>
              </mat-form-field>
            </div>
            <div>
              <div class="col-form-label">{{'lbl_to_date'| translate}}</div>
              <mat-form-field appearance="outline" class="d-block w-100 "
                (click)="toggleMenuService.togglePickerStyles()">
                <input matInput [matDatepicker]="FilterPickerTo" [max]="dateTo"
                  placeholder="{{ 'lbl_to_date' |translate}}" [(ngModel)]="dateTo" name="toDate" [readonly]="true"
                  (focus)="FilterPickerTo.open()" (click)="toggleMenuService.togglePickerStyles()">
                <mat-datepicker-toggle matSuffix [for]="FilterPickerTo"
                  (click)="toggleMenuService.togglePickerStyles()">
                </mat-datepicker-toggle>
                <mat-datepicker #FilterPickerTo></mat-datepicker>
              </mat-form-field>
            </div>
          </div>
          <div class="modal-footer p-0" style="margin-bottom: 20px;justify-content: center;">
            <div class="float-right d-inline">
              <button type="button" class="btn btn-secondary filterbtn"
                title="{{ 'tooltip_lbl_clear_filter' |translate}}" (click)="drawer.toggle();clearSearch();">
                <span>{{'button_lbl_clear'| translate}}</span>
              </button>
              <button type="button" class="btn btn-info filterbtn" title="{{ 'tooltip_lbl_filter_loans' |translate}}"
                (click)="drawer.toggle();filterLoans();">
                <span>{{'lbl_search'| translate}}</span>
              </button>
            </div>
          </div>
          <div class="px-3">
          </div>

        </mat-drawer>
      </mat-drawer-container>
    </div>
  </div>
</div>