<title>Services</title>
<app-breadcrumb [title]="'Services'" [items]="['lbl_service']" [active_item]="'Services'">
</app-breadcrumb>
<div class="container-fluid">
  <div class="row">
    <div class="col-sm-12">
      <mat-drawer-container class="example-container" autosize>
        <div class="card">
          <ng-container *ngIf="services && services.length > 0 else NoServices">
            <div class="contentcard table-responsive userlist-table">
              <table mat-table [dataSource]="services" class=" maintable mat-elevation-z8 table-striped table-vcenter"
                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="Image">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_image'| translate}}</th>
                  <td mat-cell *matCellDef="let element" style="padding: 5px;">
                    <div *ngIf="element.iconUrl else defaultServicePic">
                      <img [src]="element.iconUrl | safe" class="rounded-circle" width="50px" height="50px" alt="" />
                    </div>
                    <ng-template #defaultServicePic>
                      <div style="width:50px; height:50px" class="rounded-circle border d-flex vertical-center ">
                        <i class="fa fa-file-image m-auto" style="color:#a927f9"></i>
                      </div>
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="ServiceTypeName">
                  <th mat-header-cell *matHeaderCellDef>{{'ServiceTypeName'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.serviceTypeName else NoValue">
                      {{element.serviceTypeName}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Name">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_name'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.name else NoValue">
                      {{element.name}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="ColorCode">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_color_code'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.colorCode else NoValue">
                      {{element.colorCode}}
                    </div>
                    <ng-template #NoValue>
                      --
                    </ng-template>
                  </td>
                </ng-container>
                <ng-container matColumnDef="Description">
                  <th mat-header-cell *matHeaderCellDef>{{'lbl_description'| translate}}</th>
                  <td mat-cell *matCellDef="let element">
                    <div *ngIf="element.description else defaultdescription">
                      {{element.description}}
                    </div>
                    <ng-template #defaultdescription>
                      --
                    </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: center;display: flex;">
                    <div class="media-body text-right icon-state">
                      <label 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="element.childService && element.childService.length > 0"
                      title="{{ 'service_tooltip_child_service' |translate}}" href="javascript:;"
                      class="btn btn-sm btn-info filterbtn" (click)="element.isExpanded = !element.isExpanded;">
                      <i [ngClass]="element.isExpanded ? 'icon-angle-up' : 'icon-angle-down'"></i>
                    </a>
                    <a *ngIf="isEditPermission" title="{{ 'service_tooltip_edit_service' |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 #NoServices>

          </ng-template>

          <div class="card-footer" *ngIf="services && services.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]="servciesform">
      <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 for="name">{{'lbl_name'| translate}} <span style="color: red;">*</span></label>
          <div *ngIf="service.name else inputname">
            <input class="form-control" type="text" id="name" formControlName="name" required [readonly]="isReadonly">
          </div>
          <ng-template #inputname>
            <input class="form-control" type="text" id="name" formControlName="name" required>
          </ng-template>
          <mat-error
            *ngIf="(servciesform.get('name') && !servciesform.get('name')!.valid && servciesform.get('name')!.touched)">
            {{'message_lbl_name_is_required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="name">{{'ServiceTypeName'| translate}} <span style="color: red;">*</span></label>
          <ng-select [items]="serviceTypes" class="js-example-basic-single p-0" placeholder="Select Service Type"
            bindLabel="name" bindValue="id" name="serviceType" formControlName="serviceTypeId"></ng-select>
          <mat-error
            *ngIf="(servciesform.get('serviceTypeName') && !servciesform.get('serviceTypeName')!.valid && servciesform.get('serviceTypeName')!.touched)">
            {{'ServiceTypeName is required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="displayName">{{'lbl_display_name'| translate}} <span style="color: red;">*</span></label>
          <input class="form-control" type="text" id="displayName" formControlName="displayName" required>
          <mat-error
            *ngIf="(servciesform.get('displayName') && !servciesform.get('displayName')!.valid && servciesform.get('displayName')!.touched)">
            {{'message_lbl_display_name_is_required'| translate}}
          </mat-error>
        </div>
        <div class="form-group">
          <label for="colorcode">{{'Color Code'| translate}} </label>
          <input class="form-control" type="text" [value]="color1" id="colorCode" [(colorPicker)]="color1"
            [style.background]="color1" formControlName="colorCode">
        </div>
        <div class="form-group">
          <label for="description">{{'lbl_description'| translate}}</label>
          <textarea class="form-control" type="text" id="description" formControlName="description" rows="3"
            cols="10"></textarea>
        </div>
        <div class="form-group">
          <label for="ico">{{'lbl_image'| translate}} <span style="color: red;">*</span></label>
          <div *ngIf="!service.iconUrl else Image">
            <a class="form-control" type="upload" id="iconUrl"
              style="height: 140px; width: 100%; text-align: center; border-style: dashed; border-color: rgb(63, 105, 223);display: flex;align-items: center;"
              (click)="fileUpload.click()" required>
              <div class="absolute text-center m-auto">
                <i class="icon-plus" style="font-size:30px"></i>
                <h4>{{'lbl_in_tap_to_upload_image'| translate}}</h4>
              </div>
            </a>
          </div>
          <ng-template #Image>
            <div>
              <a type="upload" id="iconUrl" required (click)="fileUpload.click()">
                <img [src]="service.iconUrl" style=" height: 200px; width: 280px;object-fit: contain; " alt="">
              </a>
            </div>
          </ng-template>

          <input type="file" #fileUpload id="iconUrl" (change)="selectedImage($event)" name="iconUrl"
            style="display:none;" accept="image/*" />
        </div>

      </div>
      <div class="modal-footer">
        <button class="btn btn-sm btn-info filterbtn" (click)="insertServices()">
          {{'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>