<title>Banks</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Banks'" [active_item]="'Banks'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="{{ 'bank_tooltip_add_bank' |translate}}" href="javascript:;" class="btn btn-sm btn-info filterbtn"
            *ngIf="isWritePermission" (click)="modalOpen(basicmodal)">
            <i class="icon-plus"></i>
          </a>
          <button type="button" class="btn btn-info filterbtn" title="{{ 'bank_tooltip_filter_bank' |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="banks && banks.length > 0 else NoBanks">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="banks"
                class=" maintable mat-elevation-z8 table-striped table-vcenter box-shadow-none" aria-label="Banks">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef style="width:75px">#</th>
                  <td mat-cell *matCellDef="let element; let i = index;" style="width:75px">
                    {{(paginate.currentPage - 1) * paginate.pageSize + i + 1}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="bankLogo">
                  <th mat-header-cell *matHeaderCellDef style="width: 8%;">{{'lbl_image'| translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 8%;">
                    <div *ngIf="element.bankLogo else defaultServicePic">
                      <img [src]="element.bankLogo | safe" (error)="element.bankLogo = null" class="rounded-circle my-1"
                        width="50px" height="60px" alt="" style="padding-top: 8px; padding-bottom: 8px;" />
                    </div>
                    <ng-template #defaultServicePic>
                      <div style="width:50px; height:50px" class="rounded-circle border d-flex vertical-center my-1">
                        <i class="fa fa-file-image m-auto" style="color:#a927f9"></i>
                      </div>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="name">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_name'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.name else NoValue">
                      {{element.name}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="description">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_description'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.description else defaultdescription">
                      {{element.description}}
                    </div>
                    <ng-template #defaultdescription>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="headquarters">
                  <th mat-header-cell *matHeaderCellDef>{{'bank_lbl_headquarters'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.headquarters else defaultheadquarters">
                      {{element.headquarters}}
                    </div>
                    <ng-template #defaultheadquarters>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="bankCode">
                  <th mat-header-cell *matHeaderCellDef>{{'bank_lbl_bank_code'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.bankCode else defaultbankCode">
                      {{element.bankCode}}
                    </div>
                    <ng-template #defaultbankCode>
                      --
                    </ng-template>
                  </td>
                </ng-container>

                <!-- <ng-container matColumnDef="Status">
                  <th mat-header-cell *matHeaderCellDef translate>{{'lbl_status'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.isActive else InActive">
                      <span class="label text-success d-flex">
                        <span>{{'lbl_active'| translate}}</span>
                      </span>
                    </ng-container>
                    <ng-template #InActive>
                      <span class="label text-warning d-flex">
                        <span>{{'lbl_in_active'| translate}}</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; let i = index;">
                    <ng-container *ngIf="element.createdDate else NoValue">
                      {{element.createdDate | date:'medium'}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Action">
                  <th mat-header-cell *matHeaderCellDef translate class="text-right">{{'lbl_action'|
                    translate}}</th>
                  <td mat-cell *matCellDef="let element" class="text-right" style="align-items: center;display: flex;">
                    <div class="media-body text-right icon-state">
                      <label title="{{ 'tooltip_lbl_change_status' |translate}}" class="switch" style="top:7px"
                        *ngIf="isEditPermission">
                        <input type="checkbox" (click)="changeStatus(element)" [(ngModel)]="element.isActive"><span
                          class="switch-state" [ngClass]="element.isActive ? 'bg-success' : 'bg-secondary'"></span>
                      </label>
                    </div>
                    <!-- <a *ngIf="element.childbusinessAnnualProfit && element.childbusinessAnnualProfit.length > 0"
                      title="{{ 'bank_tooltip_bank' |translate}}" href="javascript:;"
                      class="btn btn-sm btn-info filterbtn" (click)="element.isExpanded = !element.isExpanded;">
                      <i [ngClass]="element.isExpanded ? 'icon-angle-up' : 'icon-angle-down'"></i>
                    </a> -->
                    <a title="{{ 'bank_tooltip_edit_bank' |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 #NoBanks>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>

          <div class="card-footer" *ngIf="banks && banks.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">
              <input class="form-control" type="text" id="search" [(ngModel)]="searchString"
                placeholder="{{'lbl_search'| translate}}" required (keypress)="keyPressAlphanumeric($event)">
            </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-sm 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-sm btn-info filterbtn"
                title="{{ 'tooltip_lbl_filter_loans' |translate}}" (click)="drawer.toggle();setPage(1);">
                <span>{{'lbl_search'| translate}}</span>
              </button>
            </div>
          </div>
          <div class="px-3">
          </div>
        </mat-drawer>

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

<ng-template #basicmodal let-modal>
  <div>
    <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" style="height:calc(100vh - 180px);overflow: auto;">
      <form [formGroup]="bankform">
        <div class="row">
          <div class="form-group col-lg-4">
            <label for="name">{{'lbl_name'| translate}} <span style="color: red;">*</span></label>
            <input class="form-control" type="text" id="name" formControlName="name" required onlyAlphabets>
            <mat-error *ngIf="(bankform.get('name') && !bankform.get('name')!.valid && bankform.get('name')!.touched)">
              {{'message_lbl_name_is_required'| translate}}
            </mat-error>
          </div>
          <div class="form-group col-lg-4">
            <label for="headquarters">{{'bank_lbl_headquarters'| translate}}</label>
            <input class="form-control" type="text" id="headquarters" formControlName="headquarters" onlyAlphabets>
          </div>
          <div class="form-group col-lg-4">
            <label for="bankCode">{{'bank_lbl_bank_code'| translate}}</label>
            <input class="form-control" type="text" id="bankCode" formControlName="bankCode" onlyNumbers>
          </div>
        </div>
        <div class="row">
          <div class="form-group col-lg-4">
            <label for="minAge">{{'bank_lbl_min_age'| translate}}</label>
            <input class="form-control" type="text" id="minAge" formControlName="minAge">
          </div>
          <div class="form-group col-lg-4">
            <label for="bankCode">{{'bank_lbl_max_age'| translate}}</label>
            <input class="form-control" type="text" id="maxAge" formControlName="maxAge">
          </div>
          <div class="form-group col-lg-4">
            <label for="description">{{'lbl_description'| translate}}</label>
            <input class="form-control" type="text" id="description" formControlName="description">
          </div>
        </div>
        <div class="form-group">
          <label for="imageUrl">{{'bank_lbl_bank_logo'| translate}} </label>
          <div *ngIf="!bankform.get('bankLogo')!.value else Image">
            <a class="form-control" type="upload" id="bankLogo"
              style="height: 150px; width: 100%; text-align: center; border-style: dashed; border-color: rgb(63, 105, 223);display: flex;align-items: center;"
              (click)="fileUpload.click()">
              <div class="absolute text-center m-auto">
                <i class="icon-plus" style="font-size:30px"></i>
                <h4>{{'lbl_in_tap_to_upload_image'| translate}}</h4>
              </div>
            </a>
          </div>
          <ng-template #Image>
            <div>
              <a class="form-control" type="upload" id="bankLogo"
                style="height: 150px; width: 100%; text-align: center; border-style: dashed; border-color: rgb(63, 105, 223);display: flex;align-items: center;">
                <div class="absolute text-center m-auto">
                  <div style="height:100px;width:100px">
                    <img [src]="bankform.get('bankLogo')!.value" style="object-fit: contain;height: 100%;width: 100%;"
                      alt="bankLogo">
                  </div>
                  <button class="btn btn-sm btn-info filterbtn" (click)="fileUpload.click()">
                    {{'button_lbl_change'| translate}}
                  </button>
                </div>
              </a>
            </div>
          </ng-template>

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


        </div>
      </form>
      <div class="row">
        <div class="col-lg-6">
          <div class="form-group">
            <label for="name">{{'bank_lbl_company_category_type'| translate}}</label>
            <ng-select [items]="companyCategoryTypes" class="js-example-basic-single p-0" bindLabel="name"
              bindValue="id" name="category" [(ngModel)]="companyCategoryType" (change)="changeCompanyCategoryType()">
            </ng-select>
          </div>
        </div>
      </div>
      <div class="row m-0 border">
        <div class="col-lg-6 border-right px-0">
          <div class="m-2">
            <h3 class=" d-inline">{{'lbl_company_category'| translate}}</h3>
            <input class="icon-rtl pl-2 d-inline float-right form-control form-control-sm" type="text" id="category"
              name="companyCategory" (keyup)="getCompanyCategory($event)" style="width:50%">
          </div>
          <div *ngIf="companyCategory && companyCategory.length > 0" class="row pl-2 m-0 border-top">
            <ul class="example-list">
              <li style="line-height:30px" *ngFor="let item  of companyCategory;let i = index">
                <input id="checkbox-info-1" type="checkbox" class="mr-2" [checked]="item.isSelected"
                  (change)="addInSelectedCategory($event,item,i)">{{item.companyName}}
              </li>
            </ul>
          </div>
        </div>
        <div class="col-lg-6 border-right px-0">
          <div class="m-2">
            <h3 class=" d-inline">{{'bank_lbl_selected_company_category'| translate}}</h3>
            <input class="icon-rtl pl-2 d-inline float-right form-control form-control-sm" type="text"
              id="Selectedcategory" name="selectedcompanyCategory" (keyup)="getCompanyCategory($event,true)"
              style="width:50%">
          </div>
          <div class="col-lg-12" *ngFor="let categoryType of bank.companyCategoryTypes">
            <h2 class="border-top border-bottom">{{categoryType.name}}</h2>
            <div *ngIf="categoryType.filterCategory && categoryType.filterCategory.length > 0" class="row pl-2 m-0">
              <ul class="example-list">
                <li style="line-height:30px" *ngFor="let item  of categoryType.filterCategory">
                  <input id="checkbox-info-1" type="checkbox" class="mr-2" [checked]="true"
                    (change)="removeFromSelectedCategory($event,item,categoryType)">
                  {{item.companyName}}
                </li>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
  <div class="modal-footer">
    <button class="btn btn-sm btn-info filterbtn" (click)="insertBank()">
      {{'button_lbl_save'| translate}}
    </button>
    <button class="btn btn-sm btn-secondary filterbtn" (click)="cancelUser()">
      {{'button_lbl_cancel'| translate}}
    </button>
  </div>
</ng-template>