<title>Training Categories</title>

<div class="container-fluid">
  <div class="row">
    <div class="col-sm-6">
      <app-breadcrumb [title]="'Training Categories'" [active_item]="'Training Categories'">
      </app-breadcrumb>
    </div>
    <div class="col-sm-6 text-right">
      <div ngbDropdown class="btn-group">
        <div class="ml-2">
          <a title="{{ 'training_category_tooltip_add_training_category' |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 autosize>
        <div class="card">
          <ng-container *ngIf="trainingCategories && trainingCategories.length > 0 else NoTrainingCategories">
            <div class="contentcard table-responsive userlist-table">
              <table class=" maintable mat-elevation-z8 table-striped table-vcenter box-shadow-none" mat-table
                [dataSource]="trainingCategories" multiTemplateDataRows aria-label="">
                <ng-container matColumnDef="id">
                  <th mat-header-cell *matHeaderCellDef style="width:75px">#</th>
                  <td mat-cell *matCellDef="let element; let i = dataIndex;" style="width:75px">
                    {{i+1}}
                    <a *ngIf="element.childTrainingCategory && element.childTrainingCategory.length > 0"
                      title="{{ 'training_category_tooltip_child_category' |translate}}" href="javascript:;"
                      (click)="element.isExpanded = !element.isExpanded;">
                      <i [ngClass]="element.isExpanded ? 'icon-angle-up' : 'icon-angle-down'"></i>
                    </a>
                  </td>
                </ng-container>
                <ng-container matColumnDef="name">
                  <th mat-header-cell *matHeaderCellDef translate>{{ 'lbl_name' | translate}} </th>
                  <td mat-cell *matCellDef="let element">
                    {{element.name}}
                  </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">
                        <span>{{ 'lbl_active' | translate}}</span>
                      </span>
                    </ng-container>
                    <ng-template #InActive>
                      <span class="label text-warning d-flex">
                        <span>{{ 'lbl_in_active' | translate}}</span>
                      </span>
                    </ng-template>
                  </td>
                </ng-container> -->
                <ng-container matColumnDef="createdDate">
                  <th mat-header-cell *matHeaderCellDef translate>{{ 'lbl_created_date' | translate}} </th>
                  <td mat-cell *matCellDef="let element">
                    {{element.createdDate | date:'medium'}}
                  </td>
                </ng-container>
                <ng-container matColumnDef="action">
                  <th mat-header-cell *matHeaderCellDef translate>{{ '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="{{ 'training_category_tooltip_active_inactive_training_category' |translate}}"
                        class="switch" style="top:7px">
                        <input type="checkbox" *ngIf="isEditPermission" (click)="changeStatus(element)"
                          [(ngModel)]="element.isActive"><span class="switch-state"
                          [ngClass]="element.isActive ? 'bg-success' : 'bg-secondary'"></span>
                      </label>
                    </div>
                    <!-- <a *ngIf="element.childTrainingCategory && element.childTrainingCategory.length > 0"
                      title="{{ 'training_category_tooltip_child_category' |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 title="{{ 'training_category_tooltip_edit_training_category' |translate}}"
                      *ngIf="isEditPermission" href="javascript:;" class="btn btn-sm btn-info filterbtn"
                      (click)="editDialog(element,basicmodal)">
                      <i class="icon-pencil"></i>
                    </a>
                    <a href="javascript:;" *ngIf="isDeletePermission" class="btn btn-sm btn-info filterbtn"
                      (click)="warningAlert(element)"
                      title="{{ 'training_category_tooltip_delete_training_category' |translate}}">
                      <i class="fa fa-trash"></i>
                    </a>
                  </td>
                </ng-container>
                <ng-container matColumnDef="expandedDetail">
                  <td mat-cell *matCellDef="let element;" [attr.colspan]="displayColumns.length">
                    <div class="row student-element-detail"
                      [@detailExpand]="element.isExpanded ? 'expanded' : 'collapsed'">
                      <table mat-table class="innerTable mat-elevation-z8" [dataSource]="element.childTrainingCategory"
                        aria-label="">
                        <ng-container matColumnDef="id">
                          <th mat-header-cell *matHeaderCellDef> <span style="font-weight:600">#</span>
                          </th>
                          <td mat-cell *matCellDef="let element;let j = index">
                            {{j + 1}}
                          </td>
                        </ng-container>
                        <ng-container matColumnDef="name">
                          <th mat-header-cell *matHeaderCellDef>
                            <span style="font-weight:600" translate>{{ 'lbl_name' | translate}}
                            </span>
                          </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="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="createdDate">
                          <th mat-header-cell *matHeaderCellDef translate>{{ 'lbl_created_date' | translate}} </th>
                          <td mat-cell *matCellDef="let element">
                            {{element.createdDate | date:'medium'}}
                          </td>
                        </ng-container>
                        <ng-container matColumnDef="action">
                          <th mat-header-cell *matHeaderCellDef translate>{{ '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">
                                <input type="checkbox" (click)="changeStatus(element)"
                                  [(ngModel)]="element.isActive"><span class="switch-state"
                                  [ngClass]="element.isActive ? 'bg-success' : 'bg-secondary'"></span>
                              </label>
                            </div>
                            <a title="{{ 'training_category_tooltip_edit_category' |translate}}" href="javascript:;"
                              class="btn btn-sm btn-info filterbtn" (click)="editDialog(element,basicmodal)">
                              <i class="icon-pencil"></i>
                            </a>
                            <a href="javascript:;" class="btn btn-sm btn-info filterbtn" (click)="warningAlert(element)"
                              title="{{ 'training_category_tooltip_delete_category' |translate}}">
                              <i class="fa fa-trash"></i>
                            </a>
                          </td>
                        </ng-container>
                        <tr mat-header-row *matHeaderRowDef="displayColumns; sticky: true" style="
                                                    width: 100%; display: table; table-layout: fixed;">
                        </tr>
                        <tr mat-row *matRowDef=" let element;let j=index; columns:displayColumns
                                                    ;" style="
                                                    width: 100%; display: table; table-layout: fixed;">
                        </tr>
                      </table>
                    </div>
                  </td>
                </ng-container>
                <tr mat-header-row *matHeaderRowDef="displayColumns; sticky: true"></tr>
                <tr mat-row *matRowDef="let element; columns: displayColumns;" class="student-element-row"
                  [class.student-expanded-row]="element.isExpanded"></tr>
                <tr mat-row *matRowDef="let row; columns: ['expandedDetail']" class="student-detail-row">
                </tr>
              </table>
            </div>
          </ng-container>
          <ng-template #NoTrainingCategories>
            <div class="d-flex vertical-center nodata">
            </div>
          </ng-template>
        </div>

      </mat-drawer-container>
    </div>
  </div>
</div>
<ng-template #basicmodal let-modal>
  <div>
    <form #TrainingCategoryForm="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">
          <label for="name">{{ 'lbl_name' | translate}} <span style="color: red;">*</span></label>
          <input class="form-control" type="text" name="cName" [(ngModel)]="trainingCategory.name"
            #CategoryName="ngModel" required>
          <mat-error *ngIf="(CategoryName!.touched) && (CategoryName.errors?.['required'])">
            {{ 'message_lbl_name_is_required' | translate}}
          </mat-error>
        </div>
        <div *ngIf="selectedTrainingCategories && selectedTrainingCategories.length > 0 && isShowParentSelection"
          class="form-group mb-2">
          <div class="col-form-label">{{ 'training_lbl_select_training_category' | translate}}</div>
          <ng-select [items]="selectedTrainingCategories" class="js-example-basic-single p-0"
            [(ngModel)]="trainingCategory.parentId"
            placeholder="{{ 'training_lbl_select_training_category' | translate}}" bindLabel="name" bindValue="id"
            name="parentCategory"></ng-select>
        </div>


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