<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="{{ 'adminPxeDescription' | translate }}">{{ 'adminPxeTitle' |
      translate }}</h2>
  </div>
  <div class="template-button-row">
    <button class="action-button" (click)="openInfoDialog()">{{ 'viewInfoButton' | translate }}</button>
    <button class="action-button" (click)="addPxeTemplate()" joyrideStep="addTemplateStep"
      text="{{ 'addTemplateButtonDescription' | translate }}">{{ 'addTemplateButton' | translate }}</button>
  </div>
</div>

<div class="search-container">
  <mat-form-field appearance="fill" class="search-string" joyrideStep="searchNameStep"
    text="{{ 'searchNameDescription' | translate }}">
    <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>
  <mat-form-field appearance="fill" class="search-boolean" joyrideStep="searchSyncStep"
    text="{{ 'searchSyncDescription' | translate }}">
    <mat-label>{{ 'createdInOgbootLabel' | translate }}</mat-label>
    <mat-select [(ngModel)]="filters['synchronized']" (selectionChange)="search()"
      placeholder="{{ 'selectOptionPlaceholder' | translate }}">
      <mat-option [value]="''">{{ 'allOption' | translate }}</mat-option>
      <mat-option [value]="true">{{ 'yesOption' | translate }}</mat-option>
      <mat-option [value]="false">{{ 'noOption' | translate }}</mat-option>
    </mat-select>
  </mat-form-field>
</div>

<app-loading [isLoading]="loading"></app-loading>
<table *ngIf="!loading" mat-table [dataSource]="dataSource" class="mat-elevation-z8" joyrideStep="tableStep"
  text="{{ 'tableDescription' | translate }}">
  <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 === 'synchronized'">
        <mat-icon [color]="image[column.columnDef] ? 'primary' : 'warn'">
          {{ image[column.columnDef] ? 'check_circle' : 'cancel' }}
        </mat-icon>
      </ng-container>
      <ng-container *ngIf="column.columnDef !== 'synchronized'">
        {{ column.cell(image) }}
      </ng-container>
    </td>
  </ng-container>

  <ng-container matColumnDef="actions">
    <th mat-header-cell *matHeaderCellDef style="text-align: center;">{{ 'actionsColumn' | translate }}</th>
    <td mat-cell *matCellDef="let template" style="text-align: center;">
      <button mat-icon-button color="info" (click)="showTemplate($event, template)">
        <mat-icon>visibility</mat-icon>
      </button>
      <button mat-icon-button color="primary" (click)="editPxeTemplate(template)">
        <mat-icon>edit</mat-icon>
      </button>
      <button mat-icon-button color="warn" (click)="toggleAction(template, 'delete')">
        <mat-icon>{{ 'deleteIcon' | translate }}</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" joyrideStep="paginationStep" text="{{ 'paginationDescription' | translate }}">
  <mat-paginator [length]="length" [pageSize]="itemsPerPage" [pageIndex]="page" [pageSizeOptions]="pageSizeOptions"
    (page)="onPageChange($event)">
  </mat-paginator>
</div>
