<!-- CONTENEDOR PRINCIPAL -->
<main class="main-container animated fadeIn">

  <!-- REGRESAR A LA PANTALLA ANTERIOR -->
  <header id="navigation" class="btn-navigate mb-8" style="width: 90% !important;">
    <div class="prev-page prevent-select indigo_primary_background mat-elevation-z8" matRipple [routerLink]="['/sam/ANFA']">
      <mat-icon style="color: white">arrow_back</mat-icon>
      <div class="page-name ml-4">Menú de Análisis de Fallas</div>
    </div>
  </header>
  <!-- CARD -->
  <mat-card class="override-card override-elevation-z8" style="width: 90% !important;">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Bitácora de Fallas</mat-card-title>
        <div class="override-actions">
          <app-search-card
            [dataSource]="dataSource"
            [disabled]="isLoading || isLoadingForm"
            (dataValue)="dataSource = $event"
          />
          <div class="override-buttons">
            <!-- <button mat-raised-button color="primary" matTooltip="Registrar Formulario" [disabled]="isLoadingForm" *ngIf="!btnSmall"
              class="override_no_shadow mr-10" (click)="openDialog('REG')">
              <mat-icon>add</mat-icon> Nuevo
            </button>
            <button mat-mini-fab color="primary" matTooltip="Registrar Formulario" [disabled]="isLoadingForm" *ngIf="btnSmall"
              class="override_no_shadow mr-8" (click)="openDialog('REG')">
              <mat-icon>add</mat-icon>
            </button> -->
            <button mat-mini-fab matTooltip="Actualizar Datos" class="cyan_dark_background white_font override_no_shadow mr-10" (click)="getFailures()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>
      <!-- ALERTAS - CARGANDO FORMULARIOS -->
      <div>
        <div class="is-loading animated fadeIn fast" *ngIf="isLoading">
          <mat-spinner align="center"></mat-spinner>
          <h3>Cargando datos ...</h3>
        </div>
        <mat-progress-bar mode="indeterminate" *ngIf="isLoadingForm"></mat-progress-bar>
      </div>
      <!-- CONTENEDOR DE LA TABLA -->
      <div class="override-table">
        <!-- TABLA -->
        <table mat-table [dataSource]="dataSource" matSort class="animated fadeIn" *ngIf="!isLoading">
          <ng-container matColumnDef="FALL_NUFA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Código de Falla</th>
            <td mat-cell *matCellDef="let element">{{ element.FALL_NUFA }}</td>
          </ng-container>
          <ng-container matColumnDef="FALL_COEQ">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Equipamiento</th>
            <td mat-cell *matCellDef="let element">{{ element.FALL_COEQ }}</td>
          </ng-container>
          <ng-container matColumnDef="LIFA_NOFA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Falla</th>
            <td mat-cell *matCellDef="let element">{{ element.LIFA_NOFA }}</td>
          </ng-container>
          <ng-container matColumnDef="FALL_CAUS">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Causa</th>
            <td mat-cell *matCellDef="let element">{{ element.FALL_CAUS }}</td>
          </ng-container>
          <ng-container matColumnDef="FALL_CLAS">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Clásificación</th>
            <td mat-cell *matCellDef="let element">
              <b *ngIf="element.FALL_CLAS === 'Bajo'" class="green_primary_font">{{ element.FALL_CLAS }}</b>
              <b *ngIf="element.FALL_CLAS === 'Intermedio'" class="light_blue_primary_font">{{ element.FALL_CLAS }}</b>
              <b *ngIf="element.FALL_CLAS === 'Alto'" class="amber_dark_font">{{ element.FALL_CLAS }}</b>
              <b *ngIf="element.FALL_CLAS === 'Crítico'" class="red_dark_font">{{ element.FALL_CLAS }}</b>
            </td>
          </ng-container>
          <ng-container matColumnDef="FALL_FEFA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Fecha de Emisión</th>
            <td mat-cell *matCellDef="let element">{{ resourcesService.formatOnlyDate(element.FALL_FEFA) }}</td>
          </ng-container>
          <ng-container matColumnDef="FALL_USRE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Usuario Modificación</th>
            <td mat-cell *matCellDef="let element">{{ resourcesService.selectUser(element.FALL_USRE, element.FALL_USMO) }}</td>
          </ng-container>
          <ng-container matColumnDef="FALL_FERE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Última Modificación</th>
            <td mat-cell *matCellDef="let element">{{ resourcesService.formatDate(element.FALL_FERE, element.FALL_FEMO) }}</td>
          </ng-container>
          <ng-container matColumnDef="FALL_ESTA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado</th>
            <td mat-cell *matCellDef="let element">
              <mat-chip-listbox>
                <mat-chip class="teal_primary_background" selected *ngIf="element.FALL_ESTA === 'Activo'"> {{ element.FALL_ESTA }} </mat-chip>
                <mat-chip class="red_dark_background" selected *ngIf="element.FALL_ESTA === 'Eliminado'"> {{ element.FALL_ESTA }} </mat-chip>
              </mat-chip-listbox>
            </td>
          </ng-container>

          <ng-container matColumnDef="ACTIONS">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let element">
              <button
                mat-mini-fab
                color="primary"
                class="override_no_shadow mr-4"
                [disabled]="element.FALL_ESTA == 'Eliminado' || isLoadingForm"
                matTooltip="Ver Diagrama"
                (click)="viewChart(element)">
                <mat-icon>bar_chart</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-20 align-center" colspan="12">
              <object data="assets/img/empty_data.svg" width="150"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
      </div>
    </section>
    <!-- PAGINADOR -->
    <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator" showFirstLastButtons></mat-paginator>
  </mat-card>
</main>
