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

  <app-btn-navigate [navigate]="'/sam/GEAD'" [nameButton]="'Menú de Despacho'" />

  <mat-card class="override-card override-elevation-z8">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Recepción de Pedidos</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]="'blue_dark_background'"
              [textColor]="'white_font'"
              [nameButton]="'Registrar Artículo sin Pedido'"
              [icon]="'add'"
              (click)="router.navigate(['sam/GEAD/DESP/REPE/register'])"/>
            <button
              mat-mini-fab
              matTooltip="Actualizar Datos"
              class="cyan_dark_background white_font override_no_shadow ml-8"
              (click)="getOrderReception()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>

      <!-- ALERTAS - CARGANDO FORMULARIOS -->
      <app-loading-card
        [isLoading]="isLoading"
        [isLoadingForm]="isLoadingForm"
        [txtLoading]="'Cargando los artículos del proveedor'"
      />

      <!-- CONTENEDOR DE LA TABLA -->
      <div class="override-table">
        <!-- TABLA -->
        <table mat-table matSort [dataSource]="dataSource" class="animated fadeIn" [style.display]="isLoading ? 'none' : 'revert'">

          <ng-container matColumnDef="ORCO_NUOR">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> No. del Pedido </th>
            <td mat-cell *matCellDef="let element"> {{ element.ORCO_NUOR }} </td>
          </ng-container>
          
          <ng-container matColumnDef="LINE_NUPR">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> No. de Proveedor </th>
            <td mat-cell *matCellDef="let element"> {{ element.LINE_NUPR }} </td>
          </ng-container>

          <ng-container matColumnDef="DESP_IDDE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> No. de Despacho </th>
            <td mat-cell *matCellDef="let element"> #{{ element.DESP_IDDE }} </td>
          </ng-container>

          <ng-container matColumnDef="DESP_NODE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Despacho </th>
            <td mat-cell *matCellDef="let element"> {{ element.DESP_NODE }} </td>
          </ng-container>
          
          <ng-container matColumnDef="ORCO_USMO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Usuario Modificación </th>
            <td mat-cell *matCellDef="let element"> {{ resourcesService.selectUser(element.ORCO_USRE, element.ORCO_USMO) }} </td>
          </ng-container>

          <ng-container matColumnDef="ORCO_FEMO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Fecha Modificación </th>
            <td mat-cell *matCellDef="let element"> {{ resourcesService.formatDate(element.ORCO_FERE, element.ORCO_FEMO) }} </td>
          </ng-container>

          <ng-container matColumnDef="ORCO_ESTA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Estado </th>
            <td mat-cell *matCellDef="let element">
              <mat-chip class="cyan_dark_background" *ngIf="element.ORCO_ESTA === 'Recibido'">
                {{ element.ORCO_ESTA }}
              </mat-chip>
              <mat-chip class="teal_dark_background" *ngIf="element.ORCO_ESTA === 'Facturado'">
                {{ element.ORCO_ESTA }}
              </mat-chip>
              <mat-chip class="deep_orange_dark_background" *ngIf="element.ORCO_ESTA === 'Devolución'">
                {{ element.ORCO_ESTA }}
              </mat-chip>
            </td>
          </ng-container>

          <ng-container matColumnDef="ACCIONES">
            <th mat-header-cell *matHeaderCellDef> Acciones </th>
            <td mat-cell *matCellDef="let element">
              <div *ngIf="resourcesService.onResize()">
                <button mat-mini-fab color="primary" [matMenuTriggerFor]="menu" #menuTrigger matTooltip="Click para desplegar las opciones" class="override_no_shadow">
                  <mat-icon>settings</mat-icon>
                </button>
                <mat-menu #menu="matMenu">
                  <button mat-menu-item (click)="getInformationOrder(element)" [disabled]="isLoadingForm">
                    <mat-icon>info</mat-icon>
                    Ver información
                  </button>
                  <button mat-menu-item (click)="openDialog('WARNING', element)" [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm">
                    <mat-icon>warning</mat-icon>
                    Reportar problema
                  </button>
                </mat-menu>
              </div>
              <div *ngIf="!resourcesService.onResize()">
                <button
                  mat-mini-fab
                  color="primary"
                  class="override_no_shadow mr-4"
                  matTooltip="Ver Detalle del Pedido"
                  (click)="getInformationOrder(element)"
                  [disabled]="isLoadingForm">
                  <mat-icon>info</mat-icon>
                </button>
                <button mat-mini-fab color="warn" class="override_no_shadow mr-4" matTooltip="Reportar problema"
                  [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm" (click)="openDialog('WARNING', element)">
                  <mat-icon>warning</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>
    <!-- PAGINADOR -->
    <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator"></mat-paginator>
  </mat-card>
