<title>User ScratchCard</title>

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

          <button *ngIf="userScratchCard && userScratchCard.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="{{ 'user_scratch_card_tooltip_filter_user_scratch_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">
          <ng-container *ngIf="userScratchCard && userScratchCard.length > 0 else NoScratchCard">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="userScratchCard"
                class=" maintable mat-elevation-z8 table-striped table-vcenter box-shadow-none" aria-label="">
                <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="user">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_user'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.fullName else NoValue">
                      {{element.fullName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="contact">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_contact_no'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.contactNo else NoValue">
                      {{element.contactNo}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="userRole">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_role'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.roleName else NoValue">
                      {{element.roleName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="rewardType">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_reward_type'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.rewardType else NoValue">
                      {{element.rewardType}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="value">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_value'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.value else NoValue">
                      {{element.value}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="isScratched">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_scratched'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <ng-container *ngIf="element.isScratched else NoScratched"> {{'lbl_true'|
                      translate}}</ng-container>
                    <ng-template #NoScratched>{{'lbl_false'| translate}}</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">
                    <div *ngIf="element.createdDate else NoValue">
                      {{element.createdDate | date:'medium'}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </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 #NoScratchCard>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>

          <div class="card-footer" *ngIf="userScratchCard && userScratchCard.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="fullName">{{'lbl_search'| translate}}</label>
              <input class="form-control" type="text" name="search" [(ngModel)]="searchString" />
            </div>
            <div class="form-group mb-2">
              <div class="col-form-label">{{'lbl_select_role'| translate}}</div>
              <ng-select [items]="roles" class="js-example-basic-single p-0"
                placeholder="{{'lbl_select_role'|translate}}" bindLabel="name" bindValue="id" name="rols"
                [(ngModel)]="roleId">
              </ng-select>
            </div>
            <div class="form-group mb-2">
              <div class="col-form-label">{{'message_lbl_reward_type'| translate}}</div>
              <ng-select [items]="rewardTypes" class="js-example-basic-single p-0"
                placeholder="{{'message_lbl_reward_type'| translate}}" bindLabel="name" bindValue="id" name="types"
                [(ngModel)]="rewardTypeId">
              </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 class="mt-3" style="padding-bottom: 10px;">
              <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 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="{{ '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>