<ng-container>
  <h3 class="border-bottom pb-2">{{messagePrefix + '.head' | translate}}</h3>

  <h4 id="search" class="border-bottom pb-2">{{messagePrefix + '.search.head' | translate}}
    <button (click)="clearFormAndResetResult();"
            class="btn btn-primary float-right">{{messagePrefix + '.button.see-all' | translate}}</button>
  </h4>
  <form [formGroup]="searchForm" (ngSubmit)="search(searchForm.value)" class="row">
    <div class="col-12">
      <div class="form-group input-group">
        <input type="text" name="query" id="query" formControlName="query"
               class="form-control" aria-label="Search input">
        <span class="input-group-append">
            <button type="submit"
                    class="search-button btn btn-secondary">{{ messagePrefix + '.search.button' | translate }}</button>
        </span>
      </div>
    </div>
  </form>

  <ds-pagination *ngIf="(groupsSearch | async)?.payload.totalElements > 0"
                 [paginationOptions]="configSearch"
                 [pageInfoState]="(groupsSearch | async)?.payload"
                 [collectionSize]="(groupsSearch | async)?.payload?.totalElements"
                 [hideGear]="true"
                 [hidePagerWhenSinglePage]="true"
                 (pageChange)="onPageChangeSearch($event)">

    <div class="table-responsive">
      <table id="groupsSearch" class="table table-striped table-hover table-bordered">
        <thead>
        <tr>
          <th scope="col">{{messagePrefix + '.table.id' | translate}}</th>
          <th scope="col">{{messagePrefix + '.table.name' | translate}}</th>
          <th>{{messagePrefix + '.table.edit' | translate}}</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let group of (groupsSearch | async)?.payload?.page">
          <td>{{group.id}}</td>
          <td><a (click)="groupDataService.startEditingNewGroup(group)"
                 [routerLink]="[groupDataService.getGroupEditPageRouterLink(group)]">{{group.name}}</a></td>
          <td>
            <div class="btn-group edit-field">
              <button *ngIf="(isSubgroupOfGroup(group) | async) && !(isActiveGroup(group) | async)"
                      (click)="deleteSubgroupFromGroup(group)"
                      class="btn btn-outline-danger btn-sm deleteButton"
                      title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: group.name} }}">
                <i class="fas fa-trash-alt fa-fw"></i>
              </button>

              <p *ngIf="(isActiveGroup(group) | async)">{{ messagePrefix + '.table.edit.currentGroup' | translate }}</p>

              <button *ngIf="!(isSubgroupOfGroup(group) | async) && !(isActiveGroup(group) | async)"
                      (click)="addSubgroupToGroup(group)"
                      class="btn btn-outline-primary btn-sm addButton"
                      title="{{messagePrefix + '.table.edit.buttons.add' | translate: {name: group.name} }}">
                <i class="fas fa-plus fa-fw"></i>
              </button>
            </div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </ds-pagination>

  <div *ngIf="(groupsSearch | async)?.payload.totalElements == 0 && searchDone" class="alert alert-info w-100 mb-2"
       role="alert">
    {{messagePrefix + '.no-items' | translate}}
  </div>

  <h4>{{messagePrefix + '.headSubgroups' | translate}}</h4>

  <ds-pagination *ngIf="(subgroupsOfGroup | async)?.payload.totalElements > 0"
                 [paginationOptions]="config"
                 [pageInfoState]="(subgroupsOfGroup | async)?.payload"
                 [collectionSize]="(subgroupsOfGroup | async)?.payload?.totalElements"
                 [hideGear]="true"
                 [hidePagerWhenSinglePage]="true"
                 (pageChange)="onPageChange($event)">

    <div class="table-responsive">
      <table id="subgroupsOfGroup" class="table table-striped table-hover table-bordered">
        <thead>
        <tr>
          <th scope="col">{{messagePrefix + '.table.id' | translate}}</th>
          <th scope="col">{{messagePrefix + '.table.name' | translate}}</th>
          <th>{{messagePrefix + '.table.edit' | translate}}</th>
        </tr>
        </thead>
        <tbody>
        <tr *ngFor="let group of (subgroupsOfGroup | async)?.payload?.page">
          <td>{{group.id}}</td>
          <td><a (click)="groupDataService.startEditingNewGroup(group)"
                 [routerLink]="[groupDataService.getGroupEditPageRouterLink(group)]">{{group.name}}</a></td>
          <td>
            <div class="btn-group edit-field">
              <button (click)="deleteSubgroupFromGroup(group)"
                      class="btn btn-outline-danger btn-sm deleteButton"
                      title="{{messagePrefix + '.table.edit.buttons.remove' | translate: {name: group.name} }}">
                <i class="fas fa-trash-alt fa-fw"></i>
              </button>
            </div>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
  </ds-pagination>

  <div *ngIf="(subgroupsOfGroup | async)?.payload.totalElements == 0" class="alert alert-info w-100 mb-2"
       role="alert">
    {{messagePrefix + '.no-subgroups-yet' | translate}}
  </div>

</ng-container>
