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

<h2 mat-dialog-title>Gestionar clientes en {{data.subnetName}}</h2>

<mat-dialog-content>
  <div class="search-container">
    <mat-form-field appearance="fill" class="search-string" joyrideStep="searchNameStep"
      text="Busca subredes por nombre para localizar una subred específica rápidamente.">
      <mat-label i18n="@@searchLabel">Buscar nombre del cliente</mat-label>
      <input matInput placeholder="Búsqueda" [(ngModel)]="filters['name']" i18n-placeholder="@@searchPlaceholder"
        (keyup.enter)="loadData()" i18n-placeholder="@@searchPlaceholder">
      <mat-icon matSuffix>search</mat-icon>
      <button *ngIf="filters['name']" mat-icon-button matSuffix aria-label="Clear tree search"
        (click)="filters['name'] = ''; loadData()">
        <mat-icon>close</mat-icon>
      </button>
      <mat-hint i18n="@@searchHint">Pulsar 'enter' para buscar</mat-hint>
    </mat-form-field>
    <mat-form-field appearance="fill" class="search-string" joyrideStep="searchIpStep" text="Busca clientes por IP.">
      <mat-label i18n="@@searchLabel">Buscar IP</mat-label>
      <input matInput placeholder="Búsqueda" [(ngModel)]="filters['ip']" i18n-placeholder="@@searchPlaceholder"
        (keyup.enter)="loadData()" i18n-placeholder="@@searchPlaceholder">
      <mat-icon matSuffix>search</mat-icon>
      <button *ngIf="filters['ip']" mat-icon-button matSuffix aria-label="Clear tree search"
        (click)="filters['ip'] = ''; loadData()">
        <mat-icon>close</mat-icon>
      </button>
      <mat-hint i18n="@@searchHint">Pulsar 'enter' para buscar</mat-hint>
    </mat-form-field>
    <mat-form-field appearance="fill" class="search-string" joyrideStep="searchIpStep" text="Busca clientes por la MAC">
      <mat-label i18n="@@searchLabel">Buscar Mac</mat-label>
      <input matInput placeholder="Búsqueda" [(ngModel)]="filters['mac']" i18n-placeholder="@@searchPlaceholder"
        (keyup.enter)="loadData()" i18n-placeholder="@@searchPlaceholder">
      <mat-icon matSuffix>search</mat-icon>
      <button *ngIf="filters['mac']" mat-icon-button matSuffix aria-label="Clear tree search"
        (click)="filters['mac'] = ''; loadData()">
        <mat-icon>close</mat-icon>
      </button>
      <mat-hint i18n="@@searchHint">Pulsar 'enter' para buscar</mat-hint>
    </mat-form-field>
    <mat-form-field class="form-field search-select" >
      <mat-label>Estados</mat-label>
      <mat-select [(ngModel)]="filters['status']" (selectionChange)="loadData()">
        <mat-option *ngFor="let option of status" [value]="option.value" >
          {{ option.name }}
        </mat-option>
      </mat-select>
      <button *ngIf="filters['status']" mat-icon-button matSuffix aria-label="Clear tree search" (click)="clearStatusFilter($event)">
        <mat-icon>close</mat-icon>
      </button>
    </mat-form-field>
  </div>

  <app-loading [isLoading]="loading"></app-loading>
  <table *ngIf="!loading" mat-table [dataSource]="dataSource" class="mat-elevation-z8" joyrideStep="tableStep"
    text="Visualiza y administra las subredes listadas según los filtros aplicados.">
    <ng-container *ngFor="let column of columns" [matColumnDef]="column.columnDef">
      <th mat-header-cell *matHeaderCellDef> {{ column.header }} </th>
      <td mat-cell *matCellDef="let client">
        <ng-container *ngIf="column.columnDef === 'status'">
          <img [src]="'assets/images/ordenador_' + client.status + '.png'" alt="Client Icon" class="client-image" />
        </ng-container>

        <ng-container *ngIf="column.columnDef === 'ogLive'">
          {{ client.ogLive?.date | date }}
        </ng-container>

        <ng-container *ngIf="column.columnDef === 'organizationalUnit'">
          {{ client.organizationalUnit?.path }}
        </ng-container>

        <ng-container *ngIf="column.columnDef !== 'status' && column.columnDef !== 'ogLive' && column.columnDef !== 'organizationalUnit'">
          {{ column.cell(client) }}
        </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 client" style="text-align: center;">
        <button mat-icon-button color="warn" (click)="deleteClient(client)">
          <mat-icon i18n="@@deleteElementTooltip">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 class="paginator-container" joyrideStep="paginationStep"
    text="Navega entre las páginas de subredes usando el paginador.">
    <mat-paginator [length]="length" [pageSize]="itemsPerPage" [pageIndex]="page" [pageSizeOptions]="pageSizeOptions"
      (page)="onPageChange($event)">
    </mat-paginator>
  </div>
</mat-dialog-content>

<mat-dialog-actions class="action-container">
  <button class="ordinary-button" (click)="onNoClick()">Cerrar</button>
</mat-dialog-actions>
