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

  <app-btn-navigate navigate="/sam/GEAD" nameButton="Gestión de adquisiciones" />

  <mat-card class="override-card override-elevation-z8">
    <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 raised-button-background"
              [textColor]="'white_font'" 
              [nameButton]="'Nuevo'" 
              [icon]="'add'"
            />
            <button 
              mat-mini-fab 
              class="orange_primary_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> No. </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> Nombre comercial </th>
            <td mat-cell *matCellDef="let element"> {{ element.RAZON_SOCIAL }} </td>
          </ng-container>

          <ng-container matColumnDef="NOMBRE">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Encargado </th>
            <td mat-cell *matCellDef="let element">{{ element.NOMBRE }} {{ element.PRIMER_APELLIDO }} {{ element.SEGUNDO_APELLIDO }}</td>
          </ng-container>

          <ng-container matColumnDef="RFC">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> R.F.C. o TAX ID </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"> {{ element.CORREO }} </td>
          </ng-container>
          
          <ng-container matColumnDef="TELEFONO1">
            <th mat-header-cell *matHeaderCellDef mat-sort-header> Teléfono </th>
            <td mat-cell *matCellDef="let element"> {{ element.LADA1 }}{{ element.TELEFONO1 }} </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="ACTION">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let element">
              <button 
                mat-mini-fab 
                color="primary" 
                class="override_no_shadow gray_dark_font transparent_background" 
                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>
                @if (getReferencesEnabled) {
                  <button 
                    mat-menu-item 
                    (click)="openDialog('REFE', element.REFERENCIAS)" 
                    [disabled]="isLoadingForm">
                    <mat-icon>analytics</mat-icon> Ver referencias
                  </button>
                }
                @if (contactEnabled) {
                  <button 
                    mat-menu-item 
                    (click)="openDialog('CONT', element.CONTACTOS)" 
                    [disabled]="isLoadingForm">
                    <mat-icon>contact_phone</mat-icon> Ver contactos
                  </button>
                }
                @if (conditionPaymentEnabled) {
                  <button 
                    mat-menu-item 
                    (click)="openDialog('COND', element.CONDICIONES)" 
                    [disabled]="isLoadingForm">
                    <mat-icon>contact_support</mat-icon> Ver condiciones
                  </button>
                }
                @if (conditionPurchaseEnabled) {
                  <button 
                    mat-menu-item 
                    (click)="openDialog('MEPA', element.METODOS_PAGO)"
                    [disabled]="isLoadingForm">
                    <mat-icon>account_balance_wallet</mat-icon> Ver medios de pago
                  </button>
                }
                @if (webCatalogEnabled) {
                  <button 
                    mat-menu-item 
                    (click)="openDialog('CATA', element.CATALAGOS)"
                    [disabled]="isLoadingForm">
                    <mat-icon>auto_stories</mat-icon> Ver catálogos
                  </button>
                }
                @if (websiteLinkEnabled) {
                  <button 
                    mat-menu-item 
                    (click)="alert('REDI', element)"
                    [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>
            </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>
