<title>Admin Users</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Admin Users'" [active_item]="'Admin Users'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="Add Admin User" 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="Filter Admin User" (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="users && users.length > 0 else NoUsers">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="users" class="mat-elevation-z8 table-striped table-vcenter lastcolumntable"
                style="min-width: 1500px; box-shadow: none;" aria-label="">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef style="width:5%">#</th>
                  <td mat-cell *matCellDef="let element; let i = index;" style="width:5%">
                    {{i+1}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="profilePicUrl">
                  <th mat-header-cell *matHeaderCellDef style="width: 8%;">{{ 'lbl_image' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="padding-top: 8px; padding-bottom: 8px; width: 8%;">
                    <div *ngIf="element.profilePicUrl else defaultServicePic">
                      <img [src]="element.profilePicUrl | safe" (error)="element.profilePicUrl = null"
                        class="rounded-circle" width="50px" height="50px" alt="" />
                    </div>
                    <ng-template #defaultServicePic>
                      <img src="../../../assets/admin/images/userprofile.png" class="rounded-circle" width="50px"
                        height="50px" alt="" />
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="FullName">
                  <th mat-header-cell *matHeaderCellDef style="width: 15%;">{{ 'lbl_name' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 15%;">
                    <ng-container *ngIf="element.fullName else NoValue">
                      {{element.fullName}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="ContactNo">
                  <th mat-header-cell *matHeaderCellDef style="width: 12%;">{{ 'lbl_contact_no' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 12%;">
                    <ng-container *ngIf="element.contactNo   else NoValue">
                      {{element.contactNo}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Email">
                  <th mat-header-cell *matHeaderCellDef style="width: 20%;">{{ 'lbl_email' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 20%;">
                    <ng-container *ngIf="element.email else NoValue">
                      {{element.email}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Gender">
                  <th mat-header-cell *matHeaderCellDef style="width: 7%;">{{ 'lbl_gender' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 7%;">
                    <ng-container *ngIf="element.gender else NoValue">
                      {{element.gender}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="roleName">
                  <th mat-header-cell *matHeaderCellDef style="width: 15%;">{{ 'lbl_role' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 15%;">
                    <ng-container *ngIf="element.roleName else NoValue">
                      {{element.roleName}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="designation">
                  <th mat-header-cell *matHeaderCellDef style="width: 8%;">{{ 'lbl_designation' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 8%;">
                    <ng-container *ngIf="element.designation else NoValue">
                      {{element.designation}}
                    </ng-container>
                    <ng-template #NoValue>
                      <span class="text-center">--</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="createdDate">
                  <th mat-header-cell *matHeaderCellDef style="width: 20%;">{{ 'lbl_created_date' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 20%;">
                    <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="Blocked">
                  <th mat-header-cell *matHeaderCellDef style="width: 8%;">{{ 'lbl_blocked' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 8%;">
                    <span *ngIf="element.isBlocked else NoBlock" style="color: #ff0000;">
                      {{ 'lbl_yes' | translate}}
                    </span>
                    <ng-template #NoBlock>
                      <span style="color: #0b9d0b;">{{ 'lbl_no' | translate}}</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Disabled">
                  <th mat-header-cell *matHeaderCellDef style="width: 8%;">{{ 'lbl_disabled' | translate}}</th>
                  <td mat-cell *matCellDef="let element" style="width: 8%;">
                    <span *ngIf="element.isDisabled else NoDisabled" style="color: #ff0000;">
                      {{ 'lbl_yes' | translate}}
                    </span>
                    <ng-template #NoDisabled>
                      <span style="color: #0b9d0b;">{{ 'lbl_no' | translate}}</span>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Action" stickyEnd>
                  <th mat-header-cell *matHeaderCellDef class="text-right">{{ 'lbl_action' | translate}}</th>
                  <td mat-cell *matCellDef="let element" class="text-right">
                    <button mat-button [matMenuTriggerFor]="beforeMenu" (click)="toggleMenuService.toggleMenuStyles()">
                      <a href="javascript:;" class="btn btn-sm btn-info filterbtn"
                        title="{{ 'tooltip_lbl_action' |translate}}">
                        <i class="fa fa-angle-down"></i>
                      </a></button>
                    <mat-menu #beforeMenu="matMenu" xPosition="before">
                      <div mat-menu-item class="p-0 mx-2" *ngIf="isEditPermission"
                        (click)="editDialog(element,basicmodal)">
                        <a title="{{ 'admin_user_tooltip_edit_admin_user' |translate}}" href="javascript:;"
                          class="btn btn-sm btn-info filterbtn">
                          <i class="icon-pencil"></i>
                        </a>{{ 'lbl_edit' | translate}}
                      </div>
                      <div mat-menu-item class="p-0 mx-2" *ngIf="isDeletePermission" (click)="deleteDialog(element)">
                        <a title="{{ 'admin_user_tooltip_remove_admin_user' |translate}}" href="javascript:;"
                          class="btn btn-sm btn-info filterbtn">
                          <i class="icon-trash"></i>
                        </a>{{ 'lbl_delete' | translate}}
                      </div>
                      <div mat-menu-item class="p-0 mx-2" *ngIf="isEditPermission" (click)="blockUnBlockUser(element)">
                        <a title="{{ 'admin_user_tooltip_block_unblock_admin_user' |translate}}" href="javascript:;"
                          class="btn btn-sm btn-info filterbtn">
                          <ng-container *ngIf="!element.isBlocked else disabled">
                            <i class="icon-lock"></i>
                          </ng-container>
                          <ng-template #disabled>
                            <i class="icon-unlock"></i>
                          </ng-template>
                        </a>{{ 'admin_user_lbl_block' | translate}}
                      </div>
                    </mat-menu>
                  </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 #NoUsers>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>
          <div class="card-footer" *ngIf="users && users.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 class="ml-1">{{ '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">
              <label for="fullName">{{ 'lbl_select_role' | translate}}</label>
              <ng-select [items]="roles" class="js-example-basic-single p-0" bindLabel="name" bindValue="id" name="id"
                [(ngModel)]="roleId"></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="{{ '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>
    <form #userForm="ngForm">
      <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 col-md-12 text-center">
          <div class="main-contact-info-header pt-3">
            <div *ngIf="!profilePic else upload">
              <img src="../../../assets/admin/images/userprofile.png" class="rounded-pill" width="150px" height="150px"
                alt="" (click)="fileInput.click()" />
            </div>
            <ng-template #upload>
              <img [src]="profilePic" (error)="profilePic = null" class="rounded-pill" width="150px" height="150px"
                alt="" (click)="fileInput.click()" />
            </ng-template>
          </div>
          <a>
            <input type="file" #fileInput id="uploadFile" (change)="selectedImage($event)" name="profilePicUrl"
              accept="image/*" style="display:none;" />
          </a>
          <div class="center">
            <button class="p-2 text-black" *ngIf="profilePic" (click)="removeImage()"
              style="text-align:center; border: none; border-radius:40%; font-size: 20px;">
              <i class="icon-trash"></i>
            </button>
            <button class="p-2 text-black" *ngIf="!profilePic" (click)="fileInput.click()"
              style="text-align:center; border: none; border-radius:40%; font-size: 20px;">
              <i class="icon-gallery"></i>
            </button>
          </div>
        </div>
        <div class="form-group">
          <label for="name">{{ 'lbl_name' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <input class="form-control" type="text" name="name" [(ngModel)]="user.fullName" #FullName="ngModel" required>
          <mat-error *ngIf="(FullName!!.touched) && (FullName.errors?.['required'])">
            {{ 'message_lbl_name_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="email">{{ 'lbl_email' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <input class="form-control" type="text" name="email" [(ngModel)]="user.email" #Email="ngModel"
            pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$" required>
          <mat-error *ngIf="(Email!!.touched) && (Email.errors?.['required'])">
            {{ 'message_lbl_email_is_required' | translate}}!
          </mat-error>
          <mat-error *ngIf="Email.errors?.['pattern']">
            {{ 'message_lbl_enter_valid_email' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="email">{{ 'lbl_contact_no' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <input class="form-control" type="text" name="mobile" [(ngModel)]="user.contactNo" #Contact="ngModel"
            ContactNo>
          <mat-error *ngIf="(Contact!!.touched) && (Contact.errors?.['required'])">
            {{ 'message_lbl_name_is_required' | translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="email">{{ 'lbl_gender' | translate}}</label>
          <div class="form-group m-t-15 m-checkbox-inline mb-0 custom-radio-ml ml-2">
            <div class="radio radio-primary">
              <input id="radioinline1" type="radio" name="radio1" value="Male" [checked]="user.gender=='Male'"
                [(ngModel)]="user.gender">
              <label class="mb-0" for="radioinline1">{{ 'lbl_male' | translate}}</label>
            </div>
            <div class="radio radio-primary">
              <input id="radioinline2" type="radio" name="radio1" value="Female" [checked]="user.gender=='Female'"
                [(ngModel)]="user.gender">
              <label class="mb-0" for="radioinline2">{{ 'lbl_female' | translate}}</label>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label for="pass">{{ 'lbl_password' | translate}} <span *ngIf="isRequired == true"
              style="color: red;">*</span></label>
          <div class="input-icons">
            <mat-icon matSuffix class="icon" (click)="hide = !hide">{{hide ? 'visibility'
              :'visibility_off'}}</mat-icon>
            <input class="form-control input-field" autocomplete="off" placeholder="password"
              [type]="hide ? 'text' : 'password'" [(ngModel)]="user.password" #Password="ngModel" required name="pass">
          </div>
          <mat-error *ngIf="Password.invalid && (Password.dirty ||Password!!.touched)">
            {{ 'message_lbl_password_is_required' | translate}}
          </mat-error>
        </div>

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

<ng-template #pagePermissionModal let-modal>
  <div>
    <form>
      <div class="modal-header">
        <h4 class="modal-title" id="modal-basic-title">{{ 'lbl_page_permission' | translate}}</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 - 200px);overflow: auto;font-size: 18px;line-height: 1.5;">

        <div class="row mx-0">
          <div class="col-sm-6">{{ 'lbl_page' | translate}}</div>
          <div class="col-sm-6">
            <div class="row">
              <div class="col-sm-3">{{ 'lbl_read' | translate}}</div>
              <div class="col-sm-3">{{ 'lbl_write' | translate}}</div>
              <div class="col-sm-3">{{ 'lbl_edit' | translate}}</div>
              <div class="col-sm-3">{{ 'lbl_delete' | translate}}</div>
            </div>
          </div>
        </div>
        <div class="row mx-0">
          <ul style="width: 100%;">
            <li class="main" *ngFor="let page of pageList" style="margin: 0 0 5px 0;border-bottom: 1px solid #ddd;">
              <div class="row">
                <div [ngClass]="!(page.children && page.children.length > 0) ? 'col-sm-6' : 'col-sm-12'">
                  <input id="checkbox-info-1" type="checkbox" [checked]="page.isChecked"
                    (click)="onCheckTreeview(page)">
                  <span class="pl-2">{{page.title}}</span>
                  <ul *ngIf="page.children && page.children.length > 0" style="margin: 0 0 0 20px;">
                    <li *ngFor="let child of page.children" class="sub pl-2">
                      <div class="row">
                        <div class="col-sm-6">
                          <input id="checkbox-info-1" type="checkbox" [checked]="child.isChecked"
                            (click)="onCheckTreeview(child)">
                          <span class="pl-1"> {{child.title}}</span>
                        </div>
                        <div class="col-sm-6">
                          <div class="row" *ngIf="child.isChecked">
                            <span class="col-sm-3">
                              <input id="checkbox-info-2" type="checkbox" [checked]="child.readPermission"
                                (click)="onCheckReadPermission(child)">
                            </span>
                            <span class="col-sm-3">
                              <input id="checkbox-info-2" type="checkbox" [checked]="child.writePermission"
                                (click)="onCheckWritePermission(child)"></span>
                            <span class="col-sm-3">
                              <input id="checkbox-info-2" type="checkbox" [checked]="child.editPermission"
                                (click)="onCheckEditPermission(child)"></span>
                            <span class="col-sm-3">
                              <input id="checkbox-info-2" type="checkbox" [checked]="child.deletePermission"
                                (click)="onCheckDeletePermission(child)"></span>
                          </div>
                        </div>
                      </div>
                    </li>
                  </ul>
                </div>
                <div class="col-sm-6">
                  <ng-container *ngIf="!(page.children && page.children.length > 0)">
                    <div class="row" *ngIf="page.isChecked">
                      <span class="col-sm-3">
                        <input id="checkbox-info-2" type="checkbox" [checked]="page.readPermission"
                          (click)="onCheckReadPermission(page)">
                      </span>
                      <span class="col-sm-3">
                        <input id="checkbox-info-2" type="checkbox" [checked]="page.writePermission"
                          (click)="onCheckWritePermission(page)"></span>
                      <span class="col-sm-3">
                        <input id="checkbox-info-2" type="checkbox" [checked]="page.editPermission"
                          (click)="onCheckEditPermission(page)"></span>
                      <span class="col-sm-3">
                        <input id="checkbox-info-2" type="checkbox" [checked]="page.deletePermission"
                          (click)="onCheckDeletePermission(page)"></span>

                    </div>
                  </ng-container>
                </div>
              </div>
            </li>
          </ul>
        </div>

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