<div class="header-container">
  <button mat-icon-button color="primary" (click)="iniciarTour()">
    <mat-icon>help</mat-icon>
  </button>
  <div class="header-container-title">
    <h2 joyrideStep="titleStep" text="{{ 'titleStepText' | translate }}">{{ 'adminCommandGroupsTitle' | translate }}</h2>
  </div>
  <div class="command-groups-button-row">
    <button class="action-button" (click)="openCreateCommandGroupModal()" joyrideStep="addCommandGroupStep" text="{{ 'addCommandGroupStepText' | translate }}">
      {{ 'addCommandGroup' | translate }}
    </button>
  </div>
</div>

<div class="search-container" joyrideStep="searchStep" text="{{ 'searchStepText' | translate }}">
  <mat-form-field appearance="fill" class="search-string">
    <mat-label>{{ 'searchGroupNameLabel' | translate }}</mat-label>
    <input matInput placeholder="{{ 'searchPlaceholder' | translate }}" [(ngModel)]="filters['name']" (keyup.enter)="search()">
    <mat-icon matSuffix>search</mat-icon>
    <mat-hint>{{ 'searchHint' | translate }}</mat-hint>
  </mat-form-field>
</div>

<div *ngIf="loading" class="loading-container" joyrideStep="loadingStep" text="{{ 'loadingStepText' | translate }}">
  <app-loading [isLoading]="loading"></app-loading>
</div>

<div *ngIf="!loading">
  <table mat-table [dataSource]="dataSource" class="mat-elevation-z8" joyrideStep="tableStep" text="{{ 'tableStepText' | translate }}">
    <ng-container *ngFor="let column of columns" [matColumnDef]="column.columnDef">
      <th mat-header-cell *matHeaderCellDef> {{ column.header }} </th>
      <td mat-cell *matCellDef="let commandGroup">
        <ng-container *ngIf="column.columnDef !== 'commands'">
          {{ column.cell(commandGroup) }}
        </ng-container>

        <ng-container *ngIf="column.columnDef === 'commands'" joyrideStep="viewCommandsStep" text="{{ 'viewCommandsStepText' | translate }}">
          <button class="action-button" [matMenuTriggerFor]="menu">{{ 'viewCommands' | translate }}</button>
          <mat-menu #menu="matMenu">
            <button mat-menu-item *ngFor="let command of commandGroup.commands">
              {{ command.name }}
            </button>
          </mat-menu>
        </ng-container>
      </td>
    </ng-container>

    <ng-container matColumnDef="actions">
      <th mat-header-cell *matHeaderCellDef style="text-align: center;">{{ 'columnActions' | translate }}</th>
      <td mat-cell *matCellDef="let client" style="text-align: center;" joyrideStep="actionsStep" text="{{ 'actionsStepText' | translate }}">
        <button mat-icon-button color="info" (click)="viewGroupDetails(client)">
          <mat-icon>visibility</mat-icon>
        </button>
        <button mat-icon-button color="primary" (click)="editCommandGroup(client)">
          <mat-icon>edit</mat-icon>
        </button>
        <button mat-icon-button color="warn" (click)="deleteCommandGroup(client)">
          <mat-icon>delete</mat-icon>
        </button>
      </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>
</div>

<div class="paginator-container" joyrideStep="paginationStep" text="{{ 'paginationStepText' | translate }}">
  <mat-paginator [length]="length"
                 [pageSize]="itemsPerPage"
                 [pageIndex]="page"
                 [pageSizeOptions]="pageSizeOptions"
                 (page)="onPageChange($event)">
  </mat-paginator>
</div>
