<!-- CONTENEDOR PRINCIPAL -->
<main class="main-container animated fadeIn" (window:resize)="onResize()">

  <!-- REGRESAR A LA PANTALLA ANTERIOR -->
  <nav id="navigation" class="btn-navigate mb-8" style="width: 80% !important">
    <div class="prev-page prevent-select indigo_primary_background mat-elevation-z8" matRipple [routerLink]="['/sam/artitles']">
      <mat-icon style="color: white">arrow_back</mat-icon>
      <div class="page-name ml-4">Gestión de Artículos</div>
    </div>
  </nav>

  <!-- CARD -->
  <mat-card class="override-card-form override-elevation-z8">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Formulario - {{ typeForm.type === 'REGI' ? 'Registro' : 'Modificación' }} de Artículo</mat-card-title>
      </nav>
      <div>
        <div class="pl-16 pr-16">
          <mat-grid-list cols="24" rowHeight="82px" [formGroup]="formGroup">
            <mat-grid-tile colspan="4">
              <mat-form-field appearance="outline">
                <mat-label>Código</mat-label>
                <input matInput formControlName="CODIGO" maxlength="50" />
                <button mat-icon-button matSuffix><mat-icon>qr_code_scanner</mat-icon></button>
              </mat-form-field>
            </mat-grid-tile>
            <mat-grid-tile colspan="10">
              <mat-form-field appearance="outline">
                <mat-label>Nombre del Artículo</mat-label>
                <input matInput formControlName="ARTICULO" maxlength="100" />
              </mat-form-field>
            </mat-grid-tile>
            <mat-grid-tile colspan="5">
              <mat-form-field appearance="outline">
                <mat-label>Familia</mat-label>
                <mat-select formControlName="FAMILIA" (ngModelChange)="getSubfamily()">
                  <mat-option *ngFor="let family of arrFamilies" [value]="family"> {{ family.NOMBRE }} </mat-option>
                </mat-select>
              </mat-form-field>
            </mat-grid-tile>
            <mat-grid-tile colspan="5">
              <mat-form-field appearance="outline">
                <mat-label>Subfamilia</mat-label>
                <mat-select formControlName="SUBFAMILIA">
                  <mat-option *ngFor="let subfamily of arrSubfamilies" [value]="subfamily"> {{ subfamily.NOMBRE }} </mat-option>
                </mat-select>
              </mat-form-field>
            </mat-grid-tile>
          </mat-grid-list>
        </div>
        <div align="end" class="pr-16">
          <button mat-raised-button class="blue_dark_background white_font override-no-shadow ml-5 animated fadeIn fast" (click)="openDialog('FORM_INFO')">
            <mat-icon>add</mat-icon> Nuevo
          </button>
        </div>

        <!-- ALERTA - CARGANDO FORMULARIOS -->
        <div class="is-loading animated fadeIn fast" *ngIf="isLoading">
          <mat-spinner align="center"></mat-spinner>
          <h3>Cargando datos ...</h3>
        </div>

        <table mat-table [dataSource]="dataSourceInformation" matSort [style.display]="isLoading ? 'none' : 'revert'">
          <ng-container matColumnDef="IMAGEN">
            <th mat-header-cell *matHeaderCellDef>Imagén</th>
            <td mat-cell *matCellDef="let element"><img [src]="setImage(element.URLIMAGE, element)" class="url-img" /></td>
          </ng-container>
          <ng-container matColumnDef="PROVEEDOR">
            <th mat-header-cell *matHeaderCellDef>Proveedor</th>
            <td mat-cell *matCellDef="let element"> {{ resourcesService.resizeText(element.PROVEEDOR.RAZON_SOCIAL, 42) }} </td>
          </ng-container>
          <ng-container matColumnDef="DESCRIPCION">
            <th mat-header-cell *matHeaderCellDef>Descripción</th>
            <td mat-cell *matCellDef="let element"> {{ resourcesService.resizeText(element.DESCRIPCION, 42) }} </td>
          </ng-container>
          <ng-container matColumnDef="CARACTERISTICAS">
            <th mat-header-cell *matHeaderCellDef>Características</th>
            <td mat-cell *matCellDef="let element"> {{ element.CARACTERISTICAS === '' ? 'N/A' : resourcesService.resizeText(element.CARACTERISTICAS, 42) }} </td>
          </ng-container>
          <ng-container matColumnDef="CANTIDAD_DETALLES">
            <th mat-header-cell *matHeaderCellDef>Cantidad de Detalles</th>
            <td mat-cell *matCellDef="let element"> {{ countDetails(element.DETAILS) }} </td>
          </ng-container>
          <ng-container matColumnDef="ESTADO">
            <th mat-header-cell *matHeaderCellDef>Estado</th>
            <td mat-cell *matCellDef="let element">
              <mat-chip class="teal_primary_background" *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="ACCIONES">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let element">
              <button mat-mini-fab color="primary" matTooltip="Configurar" class="override-no-shadow ml-4" (click)="openDialog('DETAILS', element)" [disabled]="element.ESTADO === 'Eliminado'">
                <mat-icon>settings</mat-icon>
              </button>
              <button mat-mini-fab color="success" matTooltip="Editar" class="override-no-shadow ml-4" (click)="openDialog('FORM_INFO', element)" [disabled]="element.ESTADO === 'Eliminado'">
                <mat-icon>edit</mat-icon>
              </button>
              <button mat-mini-fab color="warn" matTooltip="Eliminar" class="override-no-shadow ml-4" (click)="openDialog('ELIM_INFO', element)" *ngIf="element.ESTADO !== 'Eliminado'">
                <mat-icon>close</mat-icon>
              </button>
              <button mat-mini-fab color="info" matTooltip="Restaurar" class="override-no-shadow ml-4" (click)="openDialog('REST_INFO', element)" *ngIf="element.ESTADO === 'Eliminado'">
                <mat-icon>autorenew</mat-icon>
              </button>
            </td>
          </ng-container>
          <tr mat-header-row *matHeaderRowDef="displayedColumnsInformation"></tr>
          <tr mat-row *matRowDef="let row; columns: displayedColumnsInformation"></tr>
          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="12">
              <object data="assets/img/empty_data.svg" width="250"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <div align="end">
          <button mat-raised-button color="primary" class="override-no-shadow mt-16 mr-16 mb-16" [disabled]="checkValidation()" (click)="openDialog(typeForm.type)">
            <mat-icon>save</mat-icon>
            {{ typeForm.type === 'REGI' ? 'Registrar' : 'Modificar' }}
          </button>
        </div>
      </div>
    </section>
  </mat-card>
</main>
