<main class="main-container animated fadeIn prevent-select" (window:resize)="onResize()">

  <div class="row-tools-bar card-view-padding">
    <button mat-raised-button class="raised-button-background mb-16" [routerLink]="['/sam/ADSI/AGCA']">
      Administración de catálogos<mat-icon>arrow_back</mat-icon>
    </button>
  </div>

  <mat-card class="override-card override-elevation-z8">
    <section class="override-section">
      <nav class="override-nav">
        <mat-card-title class="mat-card-title centre">Administrador de catálogo: {{ type }}</mat-card-title>
        <div class="override-actions">
          <mat-form-field appearance="outline" class="w-300p mr-8">
            <mat-label>Buscador</mat-label>
            <input matInput [(ngModel)]="txtBuscador" (keyup)="applyFilter($event,'INP')"
            placeholder="Ingrese la palabra a buscar" />
            <mat-icon *ngIf="txtBuscador.length === 0" matSuffix>search</mat-icon>
            <mat-icon *ngIf="txtBuscador.length > 0" class="clickable" matTooltip="Eliminar filtro"
            (click)="applyFilter('', 'EST')" matSuffix>close</mat-icon>
          </mat-form-field>
          <div class="override-buttons">
            <button mat-flat-button color="primary" class="raised-button-background mr-10 animated fadeIn" (click)="saveConfig()" 
            *ngIf="!btnSmall"  [disabled]="disableSave">
              <mat-icon>save</mat-icon> {{ isSaving ? 'Guardando configuración...' : 'Guardar configuración' }}
            </button>
            <button mat-mini-fab color="primary" class="override_no_shadow mr-10 animated fadeIn raised-button-background " (click)="saveConfig()" *ngIf="btnSmall" [disabled]="disableSave" 
            [matTooltip]="isSaving ? 'Guardando configuración...' : 'Guardar configuración'">
              <mat-icon>save</mat-icon>
            </button>
            <button mat-mini-fab class="orange_primary_background white_font override_no_shadow mr-10" matTooltip="Actualizar datos" (click)="init()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>

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

      <div class="override-table">
        <table mat-table [dataSource]="countriesDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Países' ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row"> {{row.COUNTRY_ID}} </td>
          </ng-container>
          
          <ng-container matColumnDef="NAME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre</th>
            <td mat-cell *matCellDef="let row"> {{row.NAME}} </td>
          </ng-container>
          
          <ng-container matColumnDef="LADA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Lada</th>
            <td mat-cell *matCellDef="let row">
              <mat-form-field appearance="outline" style="width: 96px">
                <input matInput (input)="verifyLada(lada.value, row.COUNTRY_ID)" #lada [value]="row.LADA" [id]="'lada-' + row.COUNTRY_ID">
              </mat-form-field>
            </td>
          </ng-container>
          
          <ng-container matColumnDef="NOME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nomenclatura ISO 2</th>
            <td mat-cell *matCellDef="let row">
              <mat-form-field appearance="outline" style="width: 96px">
                <input matInput (input)="verifyISO(iso.value, row.COUNTRY_ID)" #iso [value]="row.NOMECLARUTA_ISO2" [id]="'iso-' + row.COUNTRY_ID">
              </mat-form-field>
            </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="countriesDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: countriesDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="zipCodesDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Códigos postales' ? 'revert' : 'none'">
          <ng-container matColumnDef="CP">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Código postal</th>
            <td mat-cell *matCellDef="let row"> {{row.CODIGO_POSTAL}} </td>
          </ng-container>
          
          <ng-container matColumnDef="ESTADO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado</th>
            <td mat-cell *matCellDef="let row"> {{row.ESTADO}} </td>
          </ng-container>
          
          <ng-container matColumnDef="MUNICIPIO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Municipio</th>
            <td mat-cell *matCellDef="let row"> {{row.MUNICIPIO}} </td>
          </ng-container>
          
          <ng-container matColumnDef="LOCALIDAD">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Localidad</th>
            <td mat-cell *matCellDef="let row"> {{row.LOCALIDAD}} </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="zipCodesDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: zipCodesDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="statesDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Estados' ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row"> {{row.STATE_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="PAIS">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>País relacionado</th>
            <td mat-cell *matCellDef="let row"> {{row.COUNTRY_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="NOME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre del estado</th>
            <td mat-cell *matCellDef="let row"> {{row.STATE_NAME}} </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="statesDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: statesDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="citiesDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Municipios' ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row"> {{row.CITY_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="ESTADO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado relacionado</th>
            <td mat-cell *matCellDef="let row"> {{row.STATE_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="NOME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre del municipio</th>
            <td mat-cell *matCellDef="let row"> {{row.CITY_NAME}} </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="citiesDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: citiesDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="townsDataSource!" matSort class="animated fadeIn" 
          [style.display]="!isLoading && type == 'Localidades' ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row"> {{row.TOWN_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="ESTADO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado relacionado</th>
            <td mat-cell *matCellDef="let row"> {{row.STATE_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="NOME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre del municipio</th>
            <td mat-cell *matCellDef="let row"> {{row.TOWN_NAME}} </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="townsDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: townsDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="coinsDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Monedas' ? 'revert' : 'none'">
          <ng-container matColumnDef="COIN">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Moneda</th>
            <td mat-cell *matCellDef="let row"> {{row.COIN}} </td>
          </ng-container>
          
          <ng-container matColumnDef="DESCRIPTION">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Descripcion</th>
            <td mat-cell *matCellDef="let row"> {{row.DESCRIPTION}} </td>
          </ng-container>

          <tr mat-header-row *matHeaderRowDef="coinsDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: coinsDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="settingsDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Colonias' ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row"> {{row.SETTING_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="CP">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Código postal</th>
            <td mat-cell *matCellDef="let row"> {{row.CODIGO_POSTAL}} </td>
          </ng-container>
          
          <ng-container matColumnDef="NOME">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre de la colonia</th>
            <td mat-cell *matCellDef="let row"> {{row.SETTING_NAME}} </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="settingsDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: settingsDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
        <table mat-table [dataSource]="taxRegimeDataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && type == 'Régimen fiscal' ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Código del régimen fiscal</th>
            <td mat-cell *matCellDef="let row"> {{row.TAX_REGIME_KEY}} </td>
          </ng-container>
          
          <ng-container matColumnDef="DESC">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Descripción</th>
            <td mat-cell *matCellDef="let row"> {{row.TAX_REGIME_DESC}} </td>
          </ng-container>
          
          <ng-container matColumnDef="PHISIC">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Aplica a personas físicas</th>
            <td mat-cell *matCellDef="let row"> {{row.APPLY_PHISIC}} </td>
          </ng-container>
          
          <ng-container matColumnDef="MORAL">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Aplica a personas morales</th>
            <td mat-cell *matCellDef="let row"> {{row.APPLY_MORAL}} </td>
          </ng-container>
                
          <tr mat-header-row *matHeaderRowDef="taxRegimeDisplayedColumns"></tr>
          <tr mat-row *matRowDef="let row; columns: taxRegimeDisplayedColumns;"></tr>

          <tr class="mat-row" *matNoDataRow>
            <td class="mat-cell p-80 centre" colspan="100%">
              <object data="assets/img/empty_data.svg" width="300"></object>
              <h2>Sin datos</h2>
            </td>
          </tr>
        </table>
      </div>
    </section>  
    <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator"></mat-paginator>
  </mat-card>
</main>