<title>Service Document</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Service Documents'" [active_item]="'Service Documents'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a *ngIf="isWritePermission" title="{{ 'service_document_tooltip_add_service_document' |translate}}"
            href="javascript:;" class="btn btn-sm btn-info filterbtn iconplusbtn" (click)="modalOpen(basicmodal)">
            <i class="icon-plus"></i>
          </a>
          <button type="button" class="btn btn-info filterbtn"
            title="{{ 'service_document_tooltip_filter_service_document' |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">
          <ng-container *ngIf="serviceDocuments && serviceDocuments.length > 0 else NoDocument">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="serviceDocuments"
                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="serviceName">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_service_name'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.serviceDisplayName else NoValue">
                      {{element.serviceDisplayName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="document">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_document'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.documentName else NoValue">
                      {{element.documentName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="displayName">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_display_name'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.displayName else NoValue">
                      {{element.displayName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="noOfDocument">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_document_count'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.documentCount else NoValue">
                      {{element.documentCount}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="employmentType">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_employment_type'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.employmentType else NoValue">
                      {{element.employmentType}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>


                <ng-container matColumnDef="required">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_document_type'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div class="checkbox checkbox-primary">
                      <input id="required" type="checkbox" [checked]="element.isRequired" disabled>
                      <label for="required">{{'lbl_is_required'| translate}}</label>
                    </div>
                    <div class="checkbox checkbox-primary">
                      <input id="pdf" type="checkbox" [checked]="element.isPdf" disabled>
                      <label for="pdf">{{'lbl_is_pdf'| translate}}</label>
                    </div>
                  </td>
                </ng-container>
                <ng-container matColumnDef="newTransfer">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_new/transfer'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div class="checkbox checkbox-primary">
                      <input id="required" type="checkbox" [checked]="element.isRequiredForTransfer" disabled>
                      <label for="required">{{'lbl_transfer'| translate}}</label>
                    </div>
                    <div class="checkbox checkbox-primary">
                      <input id="pdf" type="checkbox" [checked]="element.isRequiredForNew" disabled>
                      <label for="pdf">{{'lbl_new'| translate}}</label>
                    </div>
                  </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 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="isEditPermission" title="{{ 'service_document_tooltip_edit_service_document' |translate}}"
                      href="javascript:;" class="btn btn-sm btn-info filterbtn"
                      (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 #NoDocument>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>
          <div class="card-footer" *ngIf="serviceDocuments && serviceDocuments.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="px-3 mb-3">
              <ng-select [items]="services" class="js-example-basic-single p-0" [formControl]="selectedServiceId"
                placeholder="{{'lbl_select_service'|translate}}" bindLabel="displayName" bindValue="id" name="service"
                [multiple]="true">
              </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-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 [formGroup]="documentForm">
      <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 - 200px);overflow: auto;">
        <div class="form-group">
          <label>{{'lbl_select_service'| translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="services" class="js-example-basic-single p-0" formControlName="serviceId"
            placeholder="{{'lbl_select_service'| translate}}" bindLabel="displayName" bindValue="id" name="service"
            required (change)="getServiceEmploymentTypes()">
          </ng-select>
          <mat-error
            *ngIf="(documentForm.get('serviceId') && !documentForm.get('serviceId')!.valid && documentForm.get('serviceId')!.touched)">
            {{'message_lbl_service_is_required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label>{{'lbl_select_document'| translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="documents" class="js-example-basic-single p-0" formControlName="documentId"
            placeholder="{{'lbl_select_document'| translate}}" bindLabel="name" bindValue="id" name="document" required>
          </ng-select>
          <mat-error
            *ngIf="(documentForm.get('documentId') && !documentForm.get('documentId')!.valid && documentForm.get('documentId')!.touched)">
            {{'message_lbl_document_is_required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label>{{'lbl_select_employment_type'| translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="employmentTypes" class="js-example-basic-single p-0" formControlName="employmentTypeId"
            placeholder="{{ 'placeholder_lbl_select_employment_type' |translate}}" bindLabel="employmentType"
            bindValue="employmentTypeId" name="employmentType" required>
          </ng-select>
          <mat-error
            *ngIf="(documentForm.get('employmentTypeId') && !documentForm.get('employmentTypeId')!.valid && documentForm.get('employmentTypeId')!.touched)">
            {{'message_lbl_employment_type_is_required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'lbl_display_name'| translate}} <span style="color: red;">*</span></label>
          <input class="form-control" type="text" name="displayName" formControlName="displayName" required
            onlyAlphabets>
          <mat-error
            *ngIf="(documentForm.get('displayName') && !documentForm.get('displayName')!.valid && documentForm.get('displayName')!.touched)">
            {{'message_lbl_display_name_is_required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'lbl_document_count'| translate}} <span style="color: red;">*</span></label>
          <input class="form-control" type="text" name="cName" formControlName="documentCount" required onlyNumbers>
          <mat-error
            *ngIf="(documentForm.get('documentCount') && !documentForm.get('documentCount')!.valid && documentForm.get('documentCount')!.touched)">
            {{'message_lbl_document_count_is_required'| translate}}
          </mat-error>
        </div>
        <div>
          <div class="checkbox checkbox-primary d-inline">
            <input id="inputRequired" type="checkbox" formControlName="isRequired">
            <label for="inputRequired">{{'lbl_is_required'| translate}}</label>
          </div>
          <div class="checkbox checkbox-primary d-inline ml-3">
            <input id="inputPdf" type="checkbox" formControlName="isPdf">
            <label for="inputPdf">{{'lbl_is_pdf'| translate}}</label>
          </div>
        </div>
        <div class="mt-2">
          <label for="name" class="mr-2">{{'lbl_required_for_new'| translate}}?</label>
          <div class="d-inline">
            <input id="required" type="radio" value='Yes' formControlName="requiredForNew">
            <label for="required" class="ml-2">{{'lbl_yes'| translate}}</label>
          </div>
          <div class="d-inline ml-3">
            <input id="notRequired" type="radio" value='No' formControlName="requiredForNew">
            <label for="notRequired" class="ml-2">{{'lbl_no'| translate}}</label>
          </div>
        </div>
        <div>
          <label for="name" class="mr-2">{{'lbl_required_for_transfer'| translate}}?</label>

          <div class="d-inline">
            <input id="transferRequired" type="radio" value='Yes' formControlName="requiredForTransfer">
            <label for="inputRequired" class="ml-2">{{'lbl_yes'| translate}}</label>
          </div>
          <div class="d-inline ml-3">
            <input id="notRequiredForTransfer" type="radio" value='No' formControlName="requiredForTransfer">
            <label for="inputPdf" class="ml-2">{{'lbl_no'| translate}}</label>
          </div>
        </div>
      </div>
      <div class="modal-footer">
        <button class="btn btn-info filterbtn btn-sm" (click)="insertServiceDocument(documentForm)">
          {{'button_lbl_save'| translate}}
        </button>
        <button class="btn btn-secondary filterbtn btn-sm" (click)="closeDialog()">
          {{'button_lbl_cancel'| translate}}
        </button>
      </div>
    </form>
  </div>
</ng-template>