<title>Reward Coin</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Reward Coins'" [active_item]="'Reward Coins'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="{{ 'reward_coin_tooltip_add_reward_coin' |translate}}" href="javascript:;"
            class="btn btn-sm btn-info filterbtn" *ngIf="isWritePermission" (click)="modalOpen(basicmodal)">
            <i class="icon-plus"></i>
          </a>
        </div>
      </div>
    </div>
    <div class="col-sm-12">
      <mat-drawer-container class="example-container" autosize>
        <div class="card">
          <ng-container *ngIf="rewardCoins && isFlag  else NoRewardCoin">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="rewardCoins"
                class="rewardTable maintable mat-elevation-z8 table-striped table-vcenter box-shadow-none" ia-label="">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef style="width: 8%">#</th>
                  <td mat-cell *matCellDef="let element; let i = index;" style="width:8%">
                    {{(paginate.currentPage - 1) * paginate.pageSize + i + 1}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="rewardCoin">

                  <th mat-header-cell *matHeaderCellDef>{{ 'reward_coin_lbl_reward_coin' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.rewardCoin else NoValue">
                      {{element.rewardCoin}}
                    </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="assignRole">
                  <th mat-header-cell *matHeaderCellDef style="width: 22%;">{{ 'lbl_assign_role' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 22%;">
                    <div *ngIf="element.roleName else NoValue">
                      {{element.roleName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="isScratchCard">
                  <th mat-header-cell *matHeaderCellDef>{{ 'reward_coin_lbl_is_scratch_card' | translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div>
                      <ng-container *ngIf="element.isScratchCard == 1 else NoScratched"> {{ 'lbl_true' |
                        translate}}</ng-container>
                      <ng-template #NoScratched>{{ 'lbl_false' | translate}}</ng-template>
                    </div>
                    <ng-template #NoValue>
                      --
                    </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>
                      {{element.createdDate | date:'medium'}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </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">
                        <div class="dot-label bg-success mr-1"></div>
                        <span>{{ 'lbl_active' | translate}}</span>
                      </span>
                    </ng-container>
                    <ng-template #InActive>
                      <span class="label text-warning d-flex">
                        <div class="dot-label bg-secondary mr-1"></div>
                        <span>{{ 'lbl_in_active' | translate}}</span>
                      </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: right;display: flex;">
                    <div class="media-body text-right icon-state">

                      <a title="{{ 'tooltip_lbl_edit_reward_coin' |translate}}" href="javascript:;"
                        class="btn btn-sm btn-info filterbtn text-right" *ngIf="isEditPermission"
                        style="padding: 10px 12px;border-radius: 10px;margin: 6px;"
                        (click)="editDialog(element,basicmodal)">
                        <i class="icon-pencil"></i>
                      </a>
                    </div>
                  </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 #NoRewardCoin>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>
          <div class="card-footer" *ngIf="rewardCoins && rewardCoins.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-container>
    </div>
  </div>
</div>

<ng-template #basicmodal let-modal>
  <div>
    <form [formGroup]="rewardCoinform">
      <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="rewardCoin">{{ 'reward_coin_lbl_reward_coin' | translate}} <span
              style="color: red;">*</span></label>
          <input class="form-control" type="text" id="rewardCoin" formControlName="rewardCoin" required>
          <mat-error
            *ngIf="(rewardCoinform.get('rewardCoin') && !rewardCoinform.get('rewardCoin')!.valid && rewardCoinform.get('rewardCoin')!.touched)">
            {{ 'reward_coin_message_lbl_reward_coin_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="rewardTypeId">{{ 'lbl_reward_type' | translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="rewardTypes" class="js-example-basic-single p-0"
            placeholder="{{ 'message_lbl_reward_type' | translate}}" bindLabel="name" bindValue="id" name="rewardTypeId"
            formControlName="rewardTypeId"></ng-select>
          <mat-error
            *ngIf="(rewardCoinform.get('rewardTypeId') && !rewardCoinform.get('rewardTypeId')!.valid && rewardCoinform.get('rewardTypeId')!.touched)">
            {{ 'reward_coin_message_lbl_reward_type_id_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="rewardTypeId">{{ 'lbl_select_role' | translate}}<span style="color: red;">*</span></label>
          <ng-select [items]="roles" class="js-example-basic-single p-0" placeholder="{{'lbl_select_role'|translate}}"
            bindLabel="name" bindValue="id" name="roleId" formControlName="roleIds" [multiple]="true"></ng-select>
          <mat-error
            *ngIf="(rewardCoinform.get('roleIds') && !rewardCoinform.get('roleIds')!.valid && rewardCoinform.get('roleIds')!.touched)">
            {{ 'reward_coin_message_lbl_reward_id_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="minLoanFile">{{ 'reward_coin_lbl_min_loan_file' | translate}}</label>
          <input class="form-control" type="text" id="minLoanFile" formControlName="minLoanFile">

        </div>
        <div class="form-group">
          <label for="maxLoanFile">{{ 'reward_coin_lbl_max_loan_file' | translate}}</label>
          <input class="form-control" type="text" id="maxLoanFile" formControlName="maxLoanFile">

        </div>
        <div class="form-group">
          <input id="checkbox-info-2" type="checkbox" formControlName="isScratchCard"> {{
          'reward_coin_lbl_is_scratch_card' | translate}}
        </div>

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