<title>Bank Credit Card</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Bank Credit Cards'" [active_item]="'Bank Credit Cards'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="{{'bank_credit_card_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 filterbtn"
            title="{{ 'bank_credit_card_tooltip_filter_bank_credit_card' |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 mainCard">
          <div class="listContent">
            <ng-container *ngIf="bankCreditCards && bankCreditCards.length > 0 else NoBankCreditCard">
              <div class="card" *ngFor="let credit of bankCreditCards">
                <div class="row mx-0">
                  <div class="col-lg-12 mt-2 text-right">
                    <a title="{{ 'bank_credit_card_tooltip_edit_bank_credit_card' |translate}}" href="javascript:;"
                      class="btn btn-sm btn-info filterbtn" *ngIf="isEditPermission"
                      (click)="editDialog(credit,basicmodal)">
                      <i class="icon-pencil"></i>
                    </a>
                  </div>
                </div>
                <div class="row mx-2">
                  <div class=" col-lg-6 col-md-6 col-sm-12" style="text-align: center;">
                    <div class="image">
                      <ng-container *ngIf="credit.creditCardUrl && credit.creditCardUrl != '' else default">
                        <img [src]="credit.creditCardUrl" (error)="credit.creditCardUrl = ''" alt="creditCard">
                      </ng-container>
                      <ng-template #default>
                        <img src="../../../../assets/admin/images/default.png" alt="creditCard">
                      </ng-template>
                    </div>
                  </div>
                  <div class=" col-lg-6 col-md-6 col-sm-12 mt-4">
                    <div class="table-responsive border-top userlist-table">
                      <table class="table table-border border" style="min-width: 267px;" aria-label="CreditCard">
                        <tbody>
                          <tr>
                            <td class="border-right">{{'lbl_credit_card_name' | translate}}</td>
                            <td>{{credit.creditCardName}}</td>
                          </tr>
                          <tr>
                            <td class="border-right">{{'lbl_bank_name' | translate}}</td>
                            <td>{{credit.bankName}}</td>
                          </tr>
                          <tr>
                            <td class="border-right">{{'lbl_joining_fee' | translate}}</td>
                            <td>{{credit.joiningfee | currency:"INR"}}</td>
                          </tr>
                          <tr>
                            <td class="border-right">{{'lbl_renewal_fee' | translate}}</td>
                            <td>{{credit.renualfee | currency:"INR"}}</td>
                          </tr>
                          <tr>
                            <td class="border-right">{{'lbl_created_date' | translate}}</td>
                            <td>{{credit.createdDate | date:"medium"}}</td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </div>
                  <div class="col-lg-12">
                    <h2>{{'lbl_key_feature' | translate}}</h2>
                    <p [innerHtml]="credit.keyFeatures | safeHtml"></p>
                  </div>
                  <div class="col-lg-12">
                    <h2>{{'lbl_benefits' | translate}}</h2>
                    <p [innerHtml]="credit.benifitDescription | safeHtml"></p>
                  </div>
                </div>
              </div>
            </ng-container>

            <ng-template #NoBankCreditCard>
              <div class="d-flex vertical-center" style="height:calc(100vh - 260px)">
                <img src="../../../assets/admin/images/nodatafound.jpg" class="w-100 h-100 m-auto"
                  style="object-fit: contain;" alt="NoData">
              </div>
            </ng-template>
          </div>
          <div class="card-footer" *ngIf="bankCreditCards && bankCreditCards.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">{{'lbl_bank' | translate}}</label>
              <ng-select [items]="banks" class="js-example-basic-single p-0"
                placeholder="{{'lbl_select_bank'| translate}}" bindLabel="name" bindValue="id" name="bank"
                [(ngModel)]="selectedBank"></ng-select>
            </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="{{ '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="row">
          <div class="col-lg-6">
            <div class="form-group">
              <label for="name">{{'lbl_bank' | translate}} <span style="color: red;">*</span></label>
              <ng-select [items]="banks" class="js-example-basic-single p-0"
                placeholder="{{'lbl_select_bank'| translate}}" bindLabel="name" bindValue="id" name="bank"
                formControlName="bankId"></ng-select>
              <mat-error
                *ngIf="(bankCreditCardForm.get('bankId') && !bankCreditCardForm.get('bankId')!.valid && bankCreditCardForm.get('bankId')!.touched)">
                {{'message_lbl_bank_id_is_required' | translate}}
              </mat-error>
            </div>
          </div>
          <div class="col-lg-6">
            <div class="form-group">
              <label for="loanName">{{'lbl_credit_card_name' | translate}} <span style="color: red;">*</span></label>
              <input class="form-control" type="text" formControlName="creditCardName" required>
              <mat-error
                *ngIf="(bankCreditCardForm.get('creditCardName') && !bankCreditCardForm.get('creditCardName')!.valid && bankCreditCardForm.get('creditCardName')!.touched)">
                {{'message_lbl_credit_card_name_is_required' | translate}}
              </mat-error>
            </div>
          </div>
          <div class="col-lg-6">
            <div class="form-group">
              <label for="loanName">{{'lbl_joining_fee' | translate}} <span style="color: red;">*</span></label>
              <input class="form-control" type="text" formControlName="joiningfee" required onlyNumbers>
              <mat-error
                *ngIf="(bankCreditCardForm.get('joiningfee') && !bankCreditCardForm.get('joiningfee')!.valid && bankCreditCardForm.get('joiningfee')!.touched)">
                {{'message_lbl_joining_fee_is_required' | translate}}
              </mat-error>
            </div>
          </div>
          <div class="col-lg-6">
            <div class="form-group">
              <label for="loanName">{{'lbl_renewal_fee' | translate}} <span style="color: red;">*</span></label>
              <input class="form-control" type="text" id="loanName" formControlName="renualfee" required onlyNumbers>
              <mat-error
                *ngIf="(bankCreditCardForm.get('renualfee') && !bankCreditCardForm.get('renualfee')!.valid && bankCreditCardForm.get('renualfee')!.touched)">
                {{'message_lbl_renual_fee_is_required' | translate}}
              </mat-error>
            </div>
          </div>
        </div>
        <div class="col-lg-12 px-0">
          <label for="name">{{'lbl_benifit_detail' | translate}} <span style="color: red;">*</span></label>
          <angular-editor formControlName="benifitDescription" [config]="config" name="benifit" class="mt-2" required>
          </angular-editor>
          <mat-error
            *ngIf="(bankCreditCardForm.get('benifitDescription') && !bankCreditCardForm.get('benifitDescription')!.valid && bankCreditCardForm.get('benifitDescription')!.touched)">
            {{'message_lbl_benifit_desc_is_required' | translate}}
          </mat-error>
        </div>
        <div class="col-lg-12 px-0 mt-1">
          <label for="name">{{'lbl_key_feature' | translate}} <span style="color: red;">*</span></label>
          <angular-editor formControlName="keyFeatures" [config]="config" name="keyFeature" class="mt-2" required>
          </angular-editor>
          <mat-error
            *ngIf="(bankCreditCardForm.get('keyFeatures') && !bankCreditCardForm.get('keyFeatures')!.valid && bankCreditCardForm.get('keyFeatures')!.touched)">
            {{'message_lbl_key_featured_required' | translate}}
          </mat-error>
        </div>
        <div class="col-lg-12 mt-3">
          <div class="form-group">
            <label for="resume">{{'lbl_credit_card_image' | translate}} <span style="color: red;">*</span></label>
            <div *ngIf="!bankCreditCardForm.get('creditCardUrl')!.value else Image">
              <a class="form-control" type="upload" id="resume"
                style="height: 140px; width: 100%; text-align: center; border-style: dashed; border-color: rgb(63, 105, 223);display: flex;align-items: center;"
                required (click)="fileUpload.click()">
                <div class="absolute text-center m-auto">
                  <i class="icon-plus" style="font-size:30px"></i>
                  <h4>{{'message_lbl_tap_to_upload_credit_card' | translate}}</h4>
                </div>
              </a>
            </div>
            <ng-template #Image>
              <div class="image">
                <a type="upload" id="resume" (click)="fileUpload.click()">
                  <img [src]="bankCreditCardForm.get('creditCardUrl')!.value" alt="creditCard">
                </a>
              </div>
            </ng-template>

            <input type="file" #fileUpload id="creditCardImg" (change)="selectedImage($event)" name="credtiCard"
              style="display:none;" accept="image/*" />
          </div>
        </div>

      </div>
      <div class="modal-footer">
        <button class="btn btn-info filterbtn" (click)="insertBankCreditCard(bankCreditCardForm)">
          {{'button_lbl_save' | translate}}
        </button>
        <button class="btn btn-secondary filterbtn" (click)="closeDialog()">
          {{'button_lbl_cancel' | translate}}
        </button>
      </div>
    </form>
  </div>
</ng-template>