<main class="main-container animated fadeIn">
  <app-btn-navigate navigate="goback" nameButton="Regresar" />
  <mat-card class="override-card override-elevation-z8">
      @if (isLoadingForm) {
          <mat-progress-bar mode="indeterminate"></mat-progress-bar>
      }
      <section class="override-section">
          <nav class="override-nav">
              <div class="w-100 align-center pv-15">
                  <span class="override-main-title">Gestión de nivel | Almacén {{ idWarehouse }} | Área {{ idArea }}</span>
              </div>
              <div class="override-actions">
                  <app-search-card 
                      [dataSource]="dataSource" 
                      [disabled]="isLoading || isLoadingForm" 
                      (dataValue)="dataSource = $event" />
  
                  <div class="override-buttons">
                      <app-btn-resize 
                          class="mr-8"
                          (click)="goForm('R')"
                          [disabled]="isLoading || isLoadingForm"
                          [backgroundColor]="'primary raised-button-background'" 
                          [textColor]="'white_font'" 
                          [nameButton]="'Nuevo'" 
                          [icon]="'add'"/>
                      <button 
                          mat-mini-fab 
                          matTooltip="Actualizar datos"
                          (click)="getLevelByAreaWarehouse()"
                          class="orange_primary_background white_font override_no_shadow ml-8">
                          <mat-icon>refresh</mat-icon>
                      </button>
                  </div>
              </div>
          </nav>
  
          <app-loading-card [isLoading]="isLoading" txtLoading="Cargando documentos" />
  
          <div class="override-table">
              <table mat-table matSort [dataSource]="dataSource" class="animated fadeIn" [style.display]="isLoading ? 'none' : 'revert'">
                  <ng-container matColumnDef="CODIGO_NIVEL">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Código </th>
                      <td mat-cell *matCellDef="let element"> {{ element.CODIGO_NIVEL }} </td>
                  </ng-container>
                  <ng-container matColumnDef="NOMBRE_NIVEL">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Nombre del nivel </th>
                      <td mat-cell *matCellDef="let element"> {{ element.NOMBRE_NIVEL }} </td>
                  </ng-container>
                  <ng-container matColumnDef="CANTIDAD_STOCK">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Cantidad en stock </th>
                      <td mat-cell *matCellDef="let element"> {{ element.CANTIDAD_STOCK }} </td>
                  </ng-container>
                  <ng-container matColumnDef="COMENTARIOS">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Comentarios </th>
                      <td mat-cell *matCellDef="let element"> {{ element.COMENTARIOS }} </td>
                  </ng-container>
                  <ng-container matColumnDef="USUARIO_MODIFICA">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Usuario actualización </th>
                      <td mat-cell *matCellDef="let element"> {{ element.USUARIO_MODIFICA }} </td>
                  </ng-container>
                  <ng-container matColumnDef="FECHA_MODIFICA">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Última modificación </th>
                      <td mat-cell *matCellDef="let element"> {{ element.FECHA_MODIFICA }} </td>
                  </ng-container>
                  <ng-container matColumnDef="ESTADO">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Estado </th>
                      <td mat-cell *matCellDef="let element"> 
                          <button mat-flat-button class="white_font" [class]="resourcesService.setChipList(element.ESTADO)">
                            {{ element.ESTADO }}
                          </button>
                      </td>
                  </ng-container>

                  <ng-container matColumnDef="ACCIONES">
                      <th mat-header-cell *matHeaderCellDef mat-sort-header> Acciones </th>
                      <td mat-cell *matCellDef="let element">
                          <button 
                              mat-mini-fab 
                              color="primary" 
                              class="override_no_shadow transparent_background gray_dark_font" 
                              matTooltip="Clic para desplegar" 
                              [matMenuTriggerFor]="menu" 
                              [disabled]="isLoadingForm"
                              #menuTrigger>
                              <mat-icon>more_vert</mat-icon>
                          </button>
                          <mat-menu #menu="matMenu">
                              <button mat-menu-item (click)="goZoneManagement(element)">
                                  <mat-icon>inbox</mat-icon> Ver zonas
                              </button>
                              <button mat-menu-item (click)="goForm('M', element)" [disabled]="element.ESTADO === 'Eliminado'">
                                  <mat-icon>edit</mat-icon> Editar nivel
                              </button>
                              <button mat-menu-item (click)="alert('ELI', element)" [disabled]="element.ESTADO === 'Eliminado'">
                                  <mat-icon>delete</mat-icon> Eliminar nivel
                              </button>
                          </mat-menu>
                      </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, 20, 50]" class="override-paginator" showFirstLastButtons></mat-paginator>
  </mat-card>
</main>