<div class="header-container">
  <div class="header-container-title">
    <h2>{{ 'adminUsersTitle' | translate }}</h2>
  </div>
  <div class="images-button-row">
    <button class="action-button" (click)="addUser()">
      {{ 'addUser' | translate }}
    </button>
  </div>
</div>

<div class="search-container">
  <mat-form-field appearance="fill" class="search-string">
    <mat-label>{{ 'searchLabel' | 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>

<app-loading [isLoading]="loading"></app-loading>

<div *ngIf="!loading">
  <table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
    <ng-container *ngFor="let column of columns" [matColumnDef]="column.columnDef">
      <th mat-header-cell *matHeaderCellDef> {{ column.header }} </th>
      <td mat-cell *matCellDef="let user">
        <ng-container *ngIf="column.columnDef === 'groupsView'">
          <mat-chip>
            {{ user[column.columnDef] === 'card' ? 'Vista tarjetas' : 'Listado' }}
          </mat-chip>
        </ng-container>
        <ng-container *ngIf="column.columnDef !== 'groupsView'">
          {{ column.cell(user) }}
        </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 user" style="text-align: center;">
        <button mat-icon-button color="primary" (click)="editUser(user)">
          <mat-icon>edit</mat-icon>
        </button>
        <button mat-icon-button color="warn" (click)="deleteUser(user)">
          <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">
  <mat-paginator [length]="length" [pageSize]="itemsPerPage" [pageIndex]="page" [pageSizeOptions]="pageSizeOptions"
    (page)="onPageChange($event)">
  </mat-paginator>
</div>