<main class="main-container animated fadeIn prevent-select" (window:resize)="onResize()">
    
  <header id="navigation" class="btn-navigate mb-8">
    <div class="prev-page prevent-select indigo_primary_background mat-elevation-z8" matRipple
      [routerLink]="['/sam/ADSI/ASWA']">
      <mat-icon style="color: white">arrow_back</mat-icon>
      <div class="page-name ml-4">Administrador del servicio web de alarmas y contadores</div>
    </div>
  </header>

  <mat-card class="override-card override-elevation-z8">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Administrar tokens</mat-card-title>
        <div class="override-actions">
          <mat-form-field appearance="outline" class="w-300p mr-8">
            <mat-label>Buscador</mat-label>
            <input matInput [(ngModel)]="txtBuscador" (keyup)="applyFilter($event,'INP')" placeholder="Ingrese la palabra a buscar" />
            <mat-icon *ngIf="txtBuscador.length === 0" matSuffix>search</mat-icon>
            <mat-icon *ngIf="txtBuscador.length > 0" class="clickable" matTooltip="Eliminar filtro" (click)="applyFilter('', 'EST')" matSuffix>close</mat-icon>
          </mat-form-field>
          <div class="override-buttons">
            <button mat-raised-button color="primary" class="override-no-shadow mr-10 animated fadeIn" (click)="generateToken()" *ngIf="!btnSmall">
              <mat-icon>add</mat-icon> Generar token
            </button>
            <button mat-mini-fab color="primary" class="override-no-shadow mr-10 animated fadeIn" (click)="generateToken()" matTooltip="Generar token" 
            *ngIf="btnSmall">
              <mat-icon>add</mat-icon>
            </button>
            <button mat-mini-fab color="info" matTooltip="Actualizar Datos" class="override-no-shadow mr-10" (click)="getData()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>

      <div>
        <div class="is-loading animated fadeIn fast" *ngIf="isLoading">
          <mat-spinner align="center"></mat-spinner>
          <h3>Cargando datos ...</h3>
        </div>
      </div>

      <div class="override-table">
        <table mat-table [dataSource]="dataSource!" matSort class="animated fadeIn" [style.display]="isLoading ? 'none' : 'revert'">
          <ng-container matColumnDef="NOMBRE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre SCADA</th>
            <td mat-cell *matCellDef="let row">{{ row.NOMBRESCADA }}</td>
          </ng-container>
          
          <ng-container matColumnDef="DESCRIPCION">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Descripción del token</th>
            <td mat-cell *matCellDef="let row">{{ row.DESCRIPCION }}</td>
          </ng-container>
          
          <ng-container matColumnDef="ESTATUS">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado</th>
            <td mat-cell *matCellDef="let row">{{ row.ESTATUS }}</td>
          </ng-container>
          
          <ng-container matColumnDef="USUARIO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Usuario modificó</th>
            <td mat-cell *matCellDef="let row">{{ getUser(row.USUARIOREGISTRO, row.USUARIOMODIFICACION) }}</td>
          </ng-container>
          
          <ng-container matColumnDef="FECHA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Última actualizacón</th>
            <td mat-cell *matCellDef="let row">{{ getDate(row.FECHAREGISTRO, row.FECHAMODIFICACION) }}</td>
          </ng-container>
          
          <ng-container matColumnDef="ACCIONES">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Acciones</th>
            <td mat-cell *matCellDef="let row" >
              <button mat-mini-fab matTooltip="Revocar token" [ngClass]="{red_primary_background: row.ESTATUS == 'Activo'}" class="no-shadow" 
              (click)="alertRevoke(row.KEY)" [disabled]="row.ESTATUS != 'Activo'">
                <mat-icon>block</mat-icon>
              </button>
            </td>
          </ng-container>

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

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
      </div>
    </section>
    <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator"></mat-paginator>
  </mat-card>

</main>