<main class="main-container animated fadeIn prevent-select" (window:resize)="onResize()">

  <div class="row-tools-bar card-view-padding">
    <button mat-raised-button class="raised-button-background mb-16" [routerLink]="['/sam/ADSI']">
      Administrador del sistema<mat-icon>arrow_back</mat-icon>
    </button>
  </div>

  <mat-card class="override-card override-elevation-z8">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Seguimiento de acciones</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-mini-fab class="orange_primary_background white_font override_no_shadow mr-20" matTooltip="Actualizar datos" (click)="getData()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>

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

      <div class="has-error animated fadeIn fast" *ngIf="!isLoading && hasError">
        <mat-icon  class="red_primary_font">error</mat-icon>
        <h3>{{ errorStr }}</h3>
      </div>

      <div class="animated fadeIn" *ngIf="!actionsMonitoringEnabled && !isLoading && !hasError">
        <h3 class="ml-20"><b>Su perfil no cuenta con los permisos necesarios para visualizar la información de esta sección.</b></h3>
      </div>

      <div class="override-table animated fadeIn" [ngClass]="{ hidden: isLoading || hasError }">
        <table mat-table [dataSource]="dataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && actionsMonitoringEnabled && !hasError ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row">{{ row.ID }}</td>
          </ng-container>

          <ng-container matColumnDef="NOMBRE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre del usuario</th>
            <td mat-cell *matCellDef="let row">{{ row.NOMBRE }}</td>
          </ng-container>

          <ng-container matColumnDef="MODULO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Módulo</th>
            <td mat-cell *matCellDef="let row">{{ row.MODULO }}</td>
          </ng-container>

          <ng-container matColumnDef="SUBMODULO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Submódulo</th>
            <td mat-cell *matCellDef="let row">{{ row.SUBMODULO }}</td>
          </ng-container>

          <ng-container matColumnDef="FUNCION">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Función</th>
            <td mat-cell *matCellDef="let row">{{ row.FUNCION }}</td>
          </ng-container>

          <ng-container matColumnDef="PANTALLA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Pantalla</th>
            <td mat-cell *matCellDef="let row">{{ row.PANTALLA }}</td>
          </ng-container>

          <ng-container matColumnDef="TIPACC">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Tipo acción</th>
            <td mat-cell *matCellDef="let row">{{ row.TIPACC }}</td>
          </ng-container>

          <ng-container matColumnDef="FECAC">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Fecha de la acción</th>
            <td mat-cell *matCellDef="let row">{{ row.FECAC }}</td>
          </ng-container>

          <ng-container matColumnDef="ACCIONES">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let row">
              <button mat-mini-fab #tooltip="matTooltip" matTooltip="Ver detalles" style="margin-left: 4px;" class="no_shadow" 
              [ngClass]="{ pink_details_background: actionsHistoryEnabled, white_font: actionsHistoryEnabled }" (click)="openActions(row.ID)" 
              [disabled]="!actionsHistoryEnabled">
                <mat-icon>visibility</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-40 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" class="no-data-image"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
      </div>
    </section>
    <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator"></mat-paginator>
  </mat-card>
</main>