<title>Visiting Cards</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Visiting Cards'" [active_item]="'Visiting Cards'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="{{ 'visiting_card_tooltip_add_visiting_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"
            title="{{ 'visiting_card_tooltip_filter_visiting_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 autosize>
        <div class="card visitcard contentcard">
          <div class="listContent">
            <ng-container *ngIf="visitingCards && visitingCards.length > 0 else NoVisitingCards">
              <div class="file-content">
                <div class="p-1 file-manager data">
                  <div class="files">
                    <ng-container>
                      <div class="row mx-0">
                        <div class="col-lg-4 col-md-6 col-sm-12" *ngFor="let visitingCard of visitingCards"
                          style="padding-top: 20px;">
                          <div class="card">
                            <div class="card-body visit">
                              <img [src]="visitingCard.location" alt="">
                              <div class="file-bottom">
                                <span *ngIf="visitingCard.roleName?.length > 0">
                                  <h6 style="font-size: 18px; padding-top: 8px;">{{visitingCard.roleName.toString()}}
                                  </h6>
                                </span>
                              </div>
                              <div class="d-inline">
                                <a title="{{ 'visiting_card_tooltip_edit_visiting_card' |translate}}"
                                  href="javascript:;" class="btn btn-sm btn-info filterbtn" *ngIf="isEditPermission"
                                  (click)="editDialog(visitingCard,basicmodal)">
                                  <i class="icon-pencil"></i>
                                </a>
                              </div>
                              <div class="media-body icon-state d-inline">
                                <label title="{{ 'visiting_card_tooltip_active_inactive_visiting_card' |translate}}"
                                  class="switch" style="top:22px;margin-left:4px" *ngIf="isEditPermission">
                                  <input type="checkbox" (click)="changeStatus(visitingCard)"
                                    [(ngModel)]="visitingCard.isActive"><span class="switch-state"
                                    [ngClass]="visitingCard.isActive ? 'bg-success' : 'bg-secondary'"></span>
                                </label>
                              </div>
                            </div>
                          </div>
                        </div>
                      </div>
                    </ng-container>
                  </div>
                </div>
              </div>
            </ng-container>
            <ng-template #NoVisitingCards>
              <div class="d-flex vertical-center nodata">
              </div>
            </ng-template>

          </div>
          <div class="card-footer" *ngIf="visitingCards && visitingCards.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="roles">{{'lbl_search'| translate}}</label>
              <ng-select [items]="roles" class="js-example-basic-single p-0"
                placeholder="{{'visiting_card_lbl_select_roles'|translate}}" bindLabel="name" bindValue="id"
                name="search" [multiple]="true" [(ngModel)]="selectedRoleIds"></ng-select>
            </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="{{ 'visiting_card_tooltip_filter_visiting_card' |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 [formGroup]="visitingCardform">
      <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="template">{{'lbl_template'| translate}} <span style="color: red;">*</span></label>
          <textarea class="form-control" type="text" id="template" formControlName="template" rows="15"
            cols="10"></textarea>
        </div>

        <div class="form-group">
          <label for="roles">{{'visiting_card_lbl_select_roles'| translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="roles" class="js-example-basic-single p-0"
            placeholder="{{'visiting_card_lbl_select_roles'|translate}}" bindLabel="name" bindValue="id" name="role"
            formControlName="roleIds" [multiple]=true></ng-select>
        </div>

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