<h1 mat-dialog-title class="prevent-select">Búsqueda de documento registrado</h1>
<div mat-dialog-content class="prevent-select">
  <mat-grid-list rowHeight="82px" cols="6" [formGroup]="searchFilters!">
    <mat-grid-tile colspan="2">
      <mat-form-field class="w-100" appearance="outline">
        <mat-label>Módulo</mat-label>
        <mat-select [formControl]="moduleControl">
          <mat-option>--Nungúno--</mat-option>
          <mat-option *ngFor="let module of modulesArr" [value]="module.code">
            {{ module.name }}
          </mat-option>
        </mat-select>
      </mat-form-field>
    </mat-grid-tile>
    <mat-grid-tile colspan="2">
      <mat-form-field class="w-100" appearance="outline">
        <mat-label>Clasificación</mat-label>
        <mat-select [formControl]="clasificationControl">
          <mat-option>--Nungúna--</mat-option>
          <mat-option *ngFor="let clas of clasificationsArr" [value]="clas.code">
            {{ clas.category }}
          </mat-option>
        </mat-select>
      </mat-form-field>
    </mat-grid-tile>
    <mat-grid-tile colspan="2">
      <mat-form-field class="w-100" appearance="outline">
        <mat-label>Rango de fechas</mat-label>
        <input matInput (click)="openDateRangePicker()" #dateRange [formControl]="datesRangeControl">
        <button [disabled]="dateRange.value == ''" mat-icon-button matSuffix (click)="clearDatesRange()">
          <mat-icon>close</mat-icon>
        </button>
      </mat-form-field>
    </mat-grid-tile>
    <mat-grid-tile colspan="2">
      <mat-form-field class="w-100" appearance="outline">
        <mat-label>Fecha de creación final</mat-label>
        <input matInput [matDatepicker]="endDatePicker" formControlName="endDateControl">
        <mat-datepicker-toggle matIconSuffix [for]="endDatePicker"></mat-datepicker-toggle>
        <mat-datepicker #endDatePicker></mat-datepicker>
      </mat-form-field>
    </mat-grid-tile>
    <mat-grid-tile colspan="2">
      <mat-form-field class="w-100" appearance="outline">
        <mat-label>Nombre del documento</mat-label>
        <input matInput formControlName="documentNameControl">
      </mat-form-field>
    </mat-grid-tile>
    <mat-grid-tile colspan="6">
      <button mat-raised-button color="primary" class="override_no_shadow mr-10" (click)="searchFiles()">Iniciar búsqueda</button>
      <button mat-raised-button color="warn" class="override_no_shadow" (click)="clearFilters()" [disabled]="!searchExecuted">Eliminar filtros</button>
    </mat-grid-tile>
    <mat-grid-tile colspan="6" rowspan="4">
      <div class="found-files-container">
        <table mat-table [dataSource]="dataSource!" class="animated fadeIn" [style.display]="isSearching ? 'none' : 'revert'">
          <ng-container matColumnDef="CODIGO">
            <th mat-header-cell *matHeaderCellDef>Código del documento</th>
            <td mat-cell *matCellDef="let row">{{ row.CODIGO }}</td>
          </ng-container>
          
          <ng-container matColumnDef="VERSION">
            <th mat-header-cell *matHeaderCellDef>Versión</th>
            <td mat-cell *matCellDef="let row">{{ row.VERSION }}</td>
          </ng-container>
          
          <ng-container matColumnDef="NOMBRE">
            <th mat-header-cell *matHeaderCellDef>Nombre</th>
            <td mat-cell *matCellDef="let row">{{ row.NOMBRE }}</td>
          </ng-container>
          
          <ng-container matColumnDef="TAMANIO">
            <th mat-header-cell *matHeaderCellDef>Tamaño</th>
            <td mat-cell *matCellDef="let row">{{ formatBytes(row.TAMANIO) }}</td>
          </ng-container>
          
          <ng-container matColumnDef="ACCIONES">
            <th mat-header-cell *matHeaderCellDef>Acciones</th>
            <td mat-cell *matCellDef="let row">
              <button mat-mini-fab class="no-shadow" color="primary" [matTooltip]="isAttached(row) ? 'Eliminar adjunto' : 'Adjuntar archivo'" (click)="attachFile(row)">
                <mat-icon>{{ isAttached(row) ? 'link_off' : 'add_link' }}</mat-icon>
              </button>
              <button mat-mini-fab class="no-shadow ml-8 green_primary_background white_font" matTooltip="Vista previa" (click)="openViewer(row)">
                <mat-icon>visibility</mat-icon>
              </button>
              <button mat-mini-fab class="no-shadow ml-8 amber_primary_background white_font" matTooltip="Descargar" (click)="downloadFile(row)">
                <mat-icon>download</mat-icon>
              </button>
              <a [id]="'download-' + row.CODIGO" target="_blank"></a>
            </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 centre" colspan="100%" *ngIf="!searchExecuted">
              Aún no se ha realizado ninguna consulta.
            </td>
            <td class="mat-cell centre" colspan="100%" *ngIf="searchExecuted">
              Su consulta no obtuvo resultados.
            </td>
          </tr>
        </table>
        <mat-progress-bar mode="indeterminate" class="w-100" *ngIf="isSearching"></mat-progress-bar>
      </div>
    </mat-grid-tile>
  </mat-grid-list>
</div>
<div mat-dialog-actions align="end">
  <button mat-button mat-dialog-close>Cancelar</button>
  <button mat-button (click)="saveFiles()" [disabled]="attachedFiles.length == 0">Continuar</button>
</div>