<main class="main-container animated fadeIn">
  <app-btn-navigate navigate="/sam/GPRS" nameButton="Gestión de personal, recursos y subcontratistas"/>

  <mat-card class="override-card override-elevation-z8">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Lista de equipos de trabajo</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" (click)="openDialog('REG')" [disabled]="isLoading || isLoadingForm" backgroundColor="raised-button-background"
            textColor="white_font"  nameButton="Nuevo" icon="add"/>
            <button mat-mini-fab matTooltip="Actualizar datos" class="orange_primary_background white_font override_no_shadow ml-8" (click)="getWorkteams()">
              <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="override-table" [ngClass]="{ hidden: isLoading || hasError }">
        <table mat-table [dataSource]="dataSource" matSort class="animated fadeIn" 
        [style.display]="!isLoading && !hasError ? 'revert' : 'none'">
          <ng-container matColumnDef="WORKTEAM_ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>No. Equipo</th>
            <td mat-cell *matCellDef="let element">{{ element.WORKTEAM_ID }}</td>
          </ng-container>

          <ng-container matColumnDef="NAME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre</th>
            <td mat-cell *matCellDef="let element">{{ element.NAME }}</td>
          </ng-container>

          <ng-container matColumnDef="SPECIALITY">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Especialidades y/u oficios</th>
            <td mat-cell *matCellDef="let element">{{ element.SPECIALITY }}</td>
          </ng-container>

          <ng-container matColumnDef="STATUS">
            <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.STATUS)">
                {{ element.STATUS }}
              </button>
            </td>
          </ng-container>

          <ng-container matColumnDef="ACCIONES">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let element">
              <button mat-mini-fab color="primary" [disabled]="isLoadingForm || element.STATUS === 'Eliminado'" [matMenuTriggerFor]="menu"
              #menuTrigger class="override_no_shadow transparent_background gray_dark_font">
                <mat-icon>more_vert</mat-icon>
              </button>
              <mat-menu #menu="matMenu">
                <button mat-menu-item (click)="openDialog('DET', element)">
                  <mat-icon>info</mat-icon> Detalles
                </button>
                <button mat-menu-item (click)="openDialog('UPD', element)">
                  <mat-icon>edit</mat-icon> Editar
                </button>
                <button mat-menu-item (click)="openDialog('DEL', element)">
                  <mat-icon>delete</mat-icon> Eliminar
                </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="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>
