<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/ASWA']">
      Administrador del servicio web de alarmas y contadores<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">Administrar servicios web</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-mini-fab class="override_no_shadow mr-10 animated fadeIn raised-button-background" (click)="openRegister('new')" *ngIf="btnSmall" 
            matTooltip="Registrar servicio web" [disabled]="!regEditWebServiceEnabled">
              <mat-icon>add</mat-icon>
            </button>
            <button mat-flat-button color="primary" class="mr-10 animated fadeIn" (click)="openRegister('new')" *ngIf="!btnSmall" 
            [disabled]="!regEditWebServiceEnabled"> 
              <mat-icon>add</mat-icon> Registrar servicio web
            </button>
            <button mat-mini-fab class="orange_primary_background white_font override_no_shadow mr-10" matTooltip="Actualizar datos" (click)="getData()">
              <mat-icon>refresh</mat-icon>
            </button>
          </div>
        </div>
      </nav>

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

      <div class="has-error animated fadeIn fast" *ngIf="!isLoading && hasError">
        <mat-icon  class="red_primary_font">error</mat-icon>
        <h3>{{ errorStr }}</h3>
      </div>

      <div class="override-table animated fadeIn" [ngClass]="{ hidden: isLoading || hasError }">
        <table mat-table [dataSource]="dataSource!" matSort class="animated fadeIn" 
        [style.display]="!isLoading && !hasError ? 'revert' : 'none'">
          <ng-container matColumnDef="ID">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>ID</th>
            <td mat-cell *matCellDef="let row">{{ row.IDSERVICIO }}</td>
          </ng-container>
          
          <ng-container matColumnDef="URL">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>URL</th>
            <td mat-cell *matCellDef="let row">{{ row.URL }}</td>
          </ng-container>
          
          <ng-container matColumnDef="DESCRIPCION">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Descripción</th>
            <td mat-cell *matCellDef="let row">{{ row.DESCRIPCION }}</td>
          </ng-container>
          
          <ng-container matColumnDef="VINCULOS">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Vinculos</th>
            <td mat-cell *matCellDef="let row">{{ row.VINCULOS }}</td>
          </ng-container>
          
          <ng-container matColumnDef="ESTATUS">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Estado</th>
            <td mat-cell *matCellDef="let row">{{ row.ESTADO }}</td>
          </ng-container>
          
          <ng-container matColumnDef="USUARIO">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Usuario</th>
            <td mat-cell *matCellDef="let row">{{ getUser(row.USUREG, row.USUMOD) }}</td>
          </ng-container>
          
          <ng-container matColumnDef="FECHA">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Última modificación</th>
            <td mat-cell *matCellDef="let row">{{ getDate(row.FECREG, row.FECMOD) }}</td>
          </ng-container>
          
          <ng-container matColumnDef="ACCIONES">
            <th mat-header-cell *matHeaderCellDef mat-sort-header>Acciones</th>
            <td mat-cell *matCellDef="let row">
              <button mat-mini-fab class="no_shadow mr-4 orange_primary_background" matTooltip="Editar servicio web" [disabled]="row.VINCULOS > 0 || !regEditWebServiceEnabled" [ngClass]="{ 
              indigo_primary_background: row.VINCULOS == 0, white_font: row.VINCULOS == 0 }" (click)="openRegister('edit', row.IDSERVICIO, row.URL, row.DESCRIPCION)">
                <mat-icon>edit</mat-icon>
              </button>
              <button mat-mini-fab class="no_shadow" [matTooltip]="row.ESTADO == 'Activo' ? 'Inactivar servicio' : 'Activar servicio'" 
              [disabled]="row.VINCULOS > 0" [ngClass]="{ red_primary_background: row.VINCULOS == 0, white_font: row.VINCULOS == 0 }" 
              (click)="changeWSstatus(row.IDSERVICIO, row.ESTADO)">
                <mat-icon>{{ row.ESTADO == 'Activo' ? 'block' : 'check_circle' }}</mat-icon>
              </button>
            </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-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>