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

<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="groupsTitleStepText" text="{{ 'groupsTitleStepText' | translate }}">
      {{ 'imagesTitle' | translate }}
    </h2>
  </div>
  <div class="images-button-row">
    <button class="action-button" (click)="addImage()">
      {{ 'addImageButton' | translate }}
    </button>
  </div>
</div>

<div class="search-container">
  <mat-form-field appearance="fill" class="search-string" joyrideStep="searchImagesField"
    text="Busca una imagen por nombre. Pulsa 'enter' para iniciar la búsqueda.">
    <mat-label>{{ 'searchLabel' | translate }}</mat-label>
    <input matInput placeholder="Búsqueda" [(ngModel)]="filters['name']" (keyup.enter)="search()"
      i18n-placeholder="@@searchPlaceholder">
    <mat-icon matSuffix>search</mat-icon>
    <mat-hint>{{ 'searchHint' | translate }}</mat-hint>
  </mat-form-field>
</div>

<table mat-table [dataSource]="dataSource" class="mat-elevation-z8" joyrideStep="imagesTable"
  text="Esta tabla muestra las imágenes disponibles.">
  <ng-container *ngFor="let column of columns" [matColumnDef]="column.columnDef">
    <th mat-header-cell *matHeaderCellDef> {{ column.header }} </th>
    <td mat-cell *matCellDef="let image">
      <ng-container *ngIf="column.columnDef === 'remotePc'">
        <mat-icon [color]="image[column.columnDef] ? 'primary' : 'warn'">
          {{ image[column.columnDef] ? 'check_circle' : 'cancel' }}
        </mat-icon>
      </ng-container>
      <ng-container *ngIf="column.columnDef === 'imageRepositories'">
        <mat-chip-set>
          <mat-chip *ngFor="let repository of image.imageRepositories"> {{ repository.imageRepository.name }} </mat-chip>
        </mat-chip-set>

      </ng-container>
      <ng-container *ngIf="column.columnDef === 'isGlobal'">
        <mat-icon [color]="image[column.columnDef] ? 'primary' : 'warn'">
          {{ image[column.columnDef] ? 'check_circle' : 'cancel' }}
        </mat-icon>
      </ng-container>
      <ng-container *ngIf="column.columnDef !== 'remotePc' && column.columnDef !== 'status' && column.columnDef !== 'isGlobal' && column.columnDef !== 'imageRepositories'">
        {{ column.cell(image) }}
      </ng-container>
    </td>
  </ng-container>

  <ng-container matColumnDef="actions">
    <th mat-header-cell *matHeaderCellDef i18n="@@columnActions" style="text-align: center;">Acciones</th>
    <td mat-cell *matCellDef="let image" style="text-align: center;">
      <button mat-icon-button color="primary" (click)="editImage($event, image)" i18n="@@editImage"> <mat-icon>edit</mat-icon></button>
    </td>
  </ng-container>
  <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
  <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>

<div class="paginator-container">
  <mat-paginator [length]="length" [pageSize]="itemsPerPage" [pageIndex]="page" [pageSizeOptions]="[5, 10, 20, 40, 100]"
    (page)="onPageChange($event)">
  </mat-paginator>
</div>
