<main class="main-container animated fadeIn" >

  <app-btn-navigate [navigate]="'/sam/ANFA'" widthPosition="5%" [nameButton]="'Menú de Análisis de Fallas'" />

  <mat-card class="override-card override-elevation-z8" style="width: 90% !important;">
    <mat-progress-bar mode="indeterminate" *ngIf="isLoadingForm"></mat-progress-bar>

    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Lista de Síntomas</mat-card-title>
        <div class="override-actions">
          <app-search-card
            [dataSource]="dataSource"
            [disabled]="isLoading || isLoadingForm"
            (dataValue)="dataSource = $event"
          />
          <div class="override-buttons">
            <app-btn-resize
              class="ml-8"
              [disabled]="isLoading || isLoadingForm"
              [backgroundColor]="'primary'"
              [textColor]="'white_font'"
              [nameButton]="'Nuevo'"
              [icon]="'add'"
              (click)="openForm('REG')"
            />
            <button 
              mat-mini-fab 
              class="cyan_dark_background white_font override_no_shadow ml-8" 
              matTooltip="Actualizar Datos" 
              (click)="getSymptoms()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>
      
      <app-loading-card 
        [isLoading]="isLoading" 
        [txtLoading]="'Cargando la lista de síntomas'"
      />

      <div class="override-table">
        <table mat-table [dataSource]="dataSource" matSort class="animated fadeIn" [style.display]="isLoading ? 'none' : 'revert'">
          <ng-container matColumnDef="ID_SINTOMA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let element">{{ element.ID_SINTOMA }}</td>
          </ng-container>
          <ng-container matColumnDef="NOMBRE_SINTOMA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Síntoma</th>
            <td mat-cell *matCellDef="let element">{{ element.NOMBRE_SINTOMA }}</td>
          </ng-container>
          <ng-container matColumnDef="CAUSA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Causa</th>
            <td mat-cell *matCellDef="let element">{{ element.CAUSA }}</td>
          </ng-container>
          <ng-container matColumnDef="CLASIFICACION">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Clásificación</th>
            <td mat-cell *matCellDef="let element">
              <mat-chip 
                [class]="resourcesService.setChipList(element.CLASIFICACION)"
                selected> {{ element.CLASIFICACION }} 
              </mat-chip>
            </td>
          </ng-container>
          <ng-container matColumnDef="LIMITE_VALOR">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Valor Límite Permitido</th>
            <td mat-cell *matCellDef="let element">{{ element.LIMITE_VALOR }}</td>
          </ng-container>
          <ng-container matColumnDef="USUARIO_REGISTRA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Usuario Modificación</th>
            <td mat-cell *matCellDef="let element">{{ element.USUARIO_REGISTRA }}</td>
          </ng-container>
          <ng-container matColumnDef="FECHA_REGISTRA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Última Modificación</th>
            <td mat-cell *matCellDef="let element">{{ element.FECHA_REGISTRA }}</td>
          </ng-container>
          <ng-container matColumnDef="ESTADO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado</th>
            <td mat-cell *matCellDef="let element">
              <mat-chip [class]="resourcesService.setChipList(element.ESTADO)" selected> {{ element.ESTADO }} </mat-chip>
            </td>
          </ng-container>

          <ng-container matColumnDef="ACTIONS">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let element">
              <div *ngIf="resourcesService.onResize()">
                <button mat-mini-fab color="accent" [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm" [matMenuTriggerFor]="menu" #menuTrigger class="override_no_shadow">
                  <mat-icon>settings</mat-icon>
                </button>
                <mat-menu #menu="matMenu">
                  <button mat-menu-item (click)="openForm('UPD', element)">
                    <mat-icon>edit</mat-icon> Editar Síntoma
                  </button>
                  <button mat-menu-item (click)="alert(element)">
                    <mat-icon>delete</mat-icon> Eliminar Síntoma
                  </button>
                </mat-menu>
              </div>
              <div *ngIf="!resourcesService.onResize()">
                <button
                  mat-mini-fab
                  color="primary"
                  class="override_no_shadow mr-4"
                  [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm"
                  matTooltip="Editar Síntoma"
                  (click)="openForm('UPD', element)">
                  <mat-icon>edit</mat-icon>
                </button>
                <button
                  mat-mini-fab
                  color="warn"
                  class="override_no_shadow mr-4"
                  [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm"
                  (click)="alert(element)"
                  matTooltip="Eliminar Síntoma">
                  <mat-icon>delete</mat-icon>
                </button>
              </div>
            </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>
    <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator"></mat-paginator>
  </mat-card>
</main>

