<title>Bank Credit Card Policy</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Bank Credit Card Policies'" [active_item]="'Bank Credit Card Policies'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="{{ 'bank_credit_card_policy_tooltip_add_bank_credit_card' |translate}}" href="javascript:;"
            class="btn btn-sm btn-info filterbtn iconplusbtn" *ngIf="isWritePermission" (click)="modalOpen(basicmodal)">
            <i class="icon-plus"></i>
          </a>
          <button type="button" class="btn btn-info filterbtn"
            title="{{ 'bank_credit_card_policy_tooltip_filter_bank_credit_card_policy' |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 class="example-container" autosize>
        <div class="card">
          <ng-container *ngIf="bankCreditCardPolicies && bankCreditCardPolicies.length > 0 else NoBankCreditCardPolicy">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="bankCreditCardPolicies"
                class="  mat-elevation-z8 table-striped table-vcenter box-shadow-none" aria-label="">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef>#</th>
                  <td mat-cell *matCellDef="let element; let i = index;">
                    {{(paginate.currentPage - 1) * paginate.pageSize + i + 1}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="bankName">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_bank_name' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.bankName else NoValue">
                      {{element.bankName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="creditCardName">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_credit_card_name' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.creditcardName else NoValue">
                      {{element.creditcardName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="employmentType">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_employment_type' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.employmentType else NoValue">
                      {{element.employmentType}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="age">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_age' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    {{element.minAge}} - {{element.maxAge}} Years
                  </td>
                </ng-container>
                <ng-container matColumnDef="minIncome">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_min_income' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.minIncome else NoMinIncome">
                      {{currency}}{{element.minIncome}}
                    </ng-container>
                    <ng-template #NoMinIncome>
                      <span>--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="createdDate">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_created_date' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.createdDate else NoCreatedDate">
                      {{element.createdDate | date:'medium'}}
                    </ng-container>
                    <ng-template #NoCreatedDate>
                      <span>--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="cibilScore">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_min_cibilScore' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.minimumCibilScore else NoCibilScore">
                      {{element.minimumCibilScore}}
                    </ng-container>
                    <ng-template #NoCibilScore>
                      <span>--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="companyCategoryType">
                  <th mat-header-cell *matHeaderCellDef>{{'bank_lbl_company_category_type' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.companyCategoryType else NoCategory">
                      {{element.companyCategoryType}}
                    </ng-container>
                    <ng-template #NoCategory>
                      <span>--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="action">
                  <th mat-header-cell *matHeaderCellDef class="text-right">{{'lbl_action' |
                    translate}}
                  </th>
                  <td mat-cell *matCellDef="let element" class="text-right">
                    <a title="{{ 'bank_credit_card_policy_tooltip_edit_bank_credit_card_policy' |translate}}"
                      href="javascript:;" class="btn btn-sm btn-info filterbtn" *ngIf="isEditPermission"
                      (click)="editDialog(element,basicmodal)">
                      <i class="icon-pencil"></i>
                    </a>
                  </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 #NoBankCreditCardPolicy>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>

          <div class="card-footer" *ngIf="bankCreditCardPolicies && bankCreditCardPolicies.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"><span>{{'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 for="name">{{'bank_lbl_min_age' | translate}}</label>
              <input class="form-control" type="text" [(ngModel)]="minAge" onlyNumbers>
            </div>
            <div class="form-group">
              <label for="name">{{'bank_lbl_max_age' | translate}}</label>
              <input class="form-control" type="text" [(ngModel)]="maxAge" onlyNumbers>
            </div>
            <div class="form-group">
              <label for="name">{{'lbl_cibil_score' | translate}}</label>
              <input class="form-control" type="text" [(ngModel)]="minCibilScore" onlyNumbers>
            </div>
            <div class="form-group">
              <label for="name">{{'lbl_bank' | translate}}</label>
              <ng-select [items]="banks" class="js-example-basic-single p-0" bindLabel="name" bindValue="id" name="bank"
                [(ngModel)]="selectedBank"></ng-select>
            </div>
            <div class="form-group">
              <label for="name">{{'lbl_company_category' | translate}}</label>
              <ng-select [items]="companyCategoryTypes" class="js-example-basic-single p-0" bindLabel="name"
                bindValue="id" name="category" [(ngModel)]="selectedCompanyCategory">
              </ng-select>
            </div>
            <div class="form-group">
              <label for="name">{{'lbl_employment_type' | translate}}</label>
              <ng-select [items]="employmentTypes" class="js-example-basic-single p-0" bindLabel="name" bindValue="id"
                name="category" [(ngModel)]="selectedEmploymentType">
              </ng-select>
            </div>
          </div>
          <div class="modal-footer px-3" style="padding-bottom: 35px;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="{{ 'bank_credit_card_tooltip_filter_training' |translate}}"
                (click)="drawer.toggle();setPage(1);">
                <span>{{'lbl_search' | translate}}</span>
              </button>
            </div>
          </div>


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

<ng-template #basicmodal let-modal>
  <div>
    <form [formGroup]="bankCreditCardForm">
      <div class="modal-header">
        <h4 class="modal-title" id="modal-basic-title">{{title}}</h4>
        <button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body pd-20">
        <div class="form-group">
          <label for="name">{{'lbl_bank_credit_card' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <ng-select [items]="bankCreditCards" class="js-example-basic-single p-0" bindLabel="bankCreditCardName"
            bindValue="id" name="bank" formControlName="bankCreditCardId">
          </ng-select>
          <mat-error
            *ngIf="(bankCreditCardForm.get('bankCreditCardId') && !bankCreditCardForm.get('bankCreditCardId')!.valid && bankCreditCardForm.get('bankCreditCardId')!.touched)">
            {{'message_lbl_credit_card_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'lbl_employment_type' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <ng-select [items]="employmentTypes" class="js-example-basic-single p-0" bindLabel="name" bindValue="id"
            name="bank" formControlName="employmentTypeId" groupBy="parentName"></ng-select>
          <mat-error
            *ngIf="(bankCreditCardForm.get('employmentTypeId') && !bankCreditCardForm.get('employmentTypeId')!.valid && bankCreditCardForm.get('employmentTypeId')!.touched)">
            {{'message_lbl_employment_type_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'lbl_min_cibilScore' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <input class="form-control" type="text" id="name" formControlName="minimumCibilScore" required onlyNumbers>
          <mat-error
            *ngIf="(bankCreditCardForm.get('minimumCibilScore') && !bankCreditCardForm.get('minimumCibilScore')!.valid && bankCreditCardForm.get('minimumCibilScore')!.touched)">
            {{'message_lbl_cibili_score_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'bank_lbl_min_age' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <input class="form-control" type="text" id="name" formControlName="minAge" required onlyNumbers>
          <mat-error
            *ngIf="(bankCreditCardForm.get('minAge') && !bankCreditCardForm.get('minAge')!.valid && bankCreditCardForm.get('minAge')!.touched)">
            {{'message_lbl_min_age_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'bank_lbl_max_age' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <input class="form-control" type="text" id="name" formControlName="maxAge" required onlyNumbers>
          <mat-error
            *ngIf="(bankCreditCardForm.get('maxAge') && !bankCreditCardForm.get('maxAge')!.valid && bankCreditCardForm.get('maxAge')!.touched)">
            {{'message_lbl_max_age_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'lbl_min_income' | translate}} <span style="color: red;">*</span></label>
          <input class="form-control" type="text" id="name" formControlName="minIncome" required onlyNumbers>
          <mat-error
            *ngIf="(bankCreditCardForm.get('minIncome') && !bankCreditCardForm.get('minIncome')!.valid && bankCreditCardForm.get('minIncome')!.touched)">
            {{'message_lbl_min_income_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'bank_lbl_company_category_type' | translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="companyCategoryTypes" class="js-example-basic-single p-0"
            placeholder="{{'lbl_select_bank'| translate}}" bindLabel="name" bindValue="id" name="bank"
            formControlName="companyCategoryTypeId" required></ng-select>
          <mat-error
            *ngIf="(bankCreditCardForm.get('companyCategoryTypeId') && !bankCreditCardForm.get('companyCategoryTypeId')!.valid && bankCreditCardForm.get('companyCategoryTypeId')!.touched)">
            {{'message_lbl_company_category_type_is_required' | translate}}
          </mat-error>
        </div>
      </div>
      <div class="modal-footer">
        <button class="btn btn-info filterbtn" (click)="insertBankCreditCardPolicy(bankCreditCardForm)">
          {{'button_lbl_save' | translate}}
        </button>
        <button class="btn btn-secondary filterbtn" (click)="closeDialog()">
          {{'button_lbl_cancel' | translate}}
        </button>
      </div>
    </form>
  </div>
</ng-template>