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

  <app-btn-navigate [navigate]="'/sam/GEAD'" [nameButton]="'Gestión de Adquisiciones'" [widthPosition]="'5%'" />

  <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"> Gestión de Proveedores </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('REGI')"
              [disabled]="isLoading || isLoadingForm"
              [backgroundColor]="'primary'" 
              [textColor]="'white_font'" 
              [nameButton]="'Nuevo'" 
              [icon]="'add'"
            />
            <button 
              mat-mini-fab 
              class="cyan_dark_background white_font override_no_shadow ml-8" 
              matTooltip="Actualizar Datos" 
              [disabled]="isLoading || isLoadingForm"
              (click)="getAllProvider()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>

      <app-loading-card 
        [isLoading]="isLoading" 
        [isLoadingForm]="isLoadingForm" 
        [txtLoading]="'Cargando los proveedores'"
      />

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

          <ng-container matColumnDef="NUMERO_PROVEEDOR">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Número Proveedor </th>
            <td mat-cell *matCellDef="let element"> {{ element.NUMERO_PROVEEDOR }} </td>
          </ng-container>

          <ng-container matColumnDef="RAZON_SOCIAL">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Proveedor </th>
            <td mat-cell *matCellDef="let element"> {{ resourcesService.resizeText(element.RAZON_SOCIAL, 37) }} </td>
          </ng-container>

          <ng-container matColumnDef="USUARIO_PROVEEDOR">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Encargado </th>
            <td mat-cell *matCellDef="let element">  {{ setName(element) }}</td>
          </ng-container>

          <ng-container matColumnDef="RFC">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> R.F.C. </th>
            <td mat-cell *matCellDef="let element"> {{ element.RFC !== null ? element.RFC : element.TAXID }} </td>
          </ng-container>

          <ng-container matColumnDef="CORREO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Correo Electrónico </th>
            <td mat-cell *matCellDef="let element"> {{ resourcesService.resizeText(element.CORREO, 17) }} </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"> {{ resourcesService.formatDate(element.FECHA_REGISTRA, 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">
              <mat-chip 
                class="teal_dark_background white_font" 
                *ngIf="element.ESTADO === 'Activo'">
                {{ element.ESTADO }}
              </mat-chip>
              <mat-chip 
                class="red_dark_background" 
                *ngIf="element.ESTADO === 'Eliminado'">
                {{ element.ESTADO }}
              </mat-chip>
            </td>
          </ng-container>

          <ng-container matColumnDef="ACTION">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let element">
              <div *ngIf="resourcesService.onResize()">
                <button 
                  mat-mini-fab 
                  color="primary" 
                  class="override_no_shadow" 
                  matTooltip="Clic para desplegar" 
                  [matMenuTriggerFor]="menu" 
                  #menuTrigger>
                  <mat-icon>more_vert</mat-icon>
                </button>
                <mat-menu #menu="matMenu">
                  <button 
                    mat-menu-item 
                    (click)="openDialog('INFO', element)"
                    [disabled]="isLoadingForm">
                    <mat-icon>info</mat-icon> Ver Información
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="alert('SHEET', element)"
                    [disabled]="isLoadingForm">
                    <mat-icon>description</mat-icon> Descargar Ficha Proveedor
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="openDialog('REFE', element.REFERENCIAS)" 
                    *ngIf="getReferencesEnabled"
                    [disabled]="isLoadingForm">
                    <mat-icon>analytics</mat-icon> Ver Referencias
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="openDialog('CONT', element.CONTACTOS)" 
                    *ngIf="contactEnabled"
                    [disabled]="isLoadingForm">
                    <mat-icon>contact_phone</mat-icon> Ver Contactos
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="openDialog('COND', element.CONDICIONES)" 
                    *ngIf="conditionPaymentEnabled"
                    [disabled]="isLoadingForm">
                    <mat-icon>contact_support</mat-icon> Ver Condiciones
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="openDialog('MEPA', element.METODOS_PAGO)"
                    *ngIf="conditionPurchaseEnabled"
                    [disabled]="isLoadingForm">
                    <mat-icon>account_balance_wallet</mat-icon> Ver Medios de Pago
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="openDialog('CATA', element.CONTACTOS)"
                    *ngIf="webCatalogEnabled"
                    [disabled]="isLoadingForm">
                    <mat-icon>auto_stories</mat-icon> Ver Catálogos
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="alert('REDI', element)"
                    *ngIf="websiteLinkEnabled"
                    [disabled]="isLoadingForm">
                    <mat-icon>public</mat-icon> Ver Sitio Web
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="openDialog('EDIT', element)"
                    [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm">
                    <mat-icon>edit</mat-icon> Editar Proveedor
                  </button>
                  <button 
                    mat-menu-item 
                    (click)="alert('ELIM', element)"
                    [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm">
                    <mat-icon>delete</mat-icon> Eliminar Proveedor
                  </button>
                </mat-menu>
              </div>
              <div *ngIf="!resourcesService.onResize()">
                <button 
                  mat-mini-fab 
                  class="blue_gray_primary_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Información" 
                  (click)="openDialog('INFO', element)"
                  [disabled]="isLoadingForm">
                  <mat-icon>info</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="amber_dark_background white_font override_no_shadow ml-4" 
                  matTooltip="Descargar Ficha Proveedor" 
                  [disabled]="isLoadingForm"
                  (click)="alert('SHEET', element)">
                  <mat-icon>description</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="deep_orange_dark_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Referencias" 
                  *ngIf="getReferencesEnabled"
                  (click)="openDialog('REFE', element.REFERENCIAS)"
                  [disabled]="isLoadingForm">
                  <mat-icon>analytics</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="brown_primary_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Contactos" 
                  *ngIf="contactEnabled"
                  (click)="openDialog('CONT', element.CONTACTOS)"
                  [disabled]="isLoadingForm">
                  <mat-icon>contact_phone</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="cyan_dark_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Condiciones" 
                  *ngIf="conditionPaymentEnabled"
                  (click)="openDialog('COND', element.CONDICIONES)" 
                  [disabled]="isLoadingForm">
                  <mat-icon>contact_support</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="green_dark_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Medios de Pago" 
                  *ngIf="conditionPurchaseEnabled"
                  (click)="openDialog('MEPA', element.METODOS_PAGO)"
                  [disabled]="isLoadingForm">
                  <mat-icon>account_balance_wallet</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="pink_dark_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Catálogos" 
                  *ngIf="webCatalogEnabled"
                  (click)="openDialog('CATA', element.CATALAGOS)"
                  [disabled]="isLoadingForm">
                  <mat-icon>auto_stories</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  class="light_blue_dark_background white_font override_no_shadow ml-4" 
                  matTooltip="Ver Sitio Web" 
                  *ngIf="websiteLinkEnabled"
                  (click)="alert('REDI', element)"
                  [disabled]="isLoadingForm">
                  <mat-icon>public</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  color="primary" 
                  class="override_no_shadow ml-4" 
                  matTooltip="Editar Proveedor"
                  (click)="openDialog('EDIT', element)" 
                  [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm">
                  <mat-icon>edit</mat-icon>
                </button>
                <button 
                  mat-mini-fab 
                  color="warn" 
                  class="override_no_shadow ml-4" 
                  matTooltip="Eliminar Proveedor"
                  (click)="alert('ELIM', element)" 
                  [disabled]="element.ESTADO == 'Eliminado' || isLoadingForm">
                  <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>
