<div class="active-orders-container prevent-select" (window:resize)="onResize()">
  <div class="active-orders-toolbar animated fadeIn">
    <div class="prev-page raised-button-background mat-elevation-z8" matRipple 
    [routerLink]="['/sam/GMCO']">
      <mat-icon style="color: white;">arrow_back</mat-icon>
      <div class="page-name ml-4">Gestión de mantenimiento correctivo</div>
    </div>
    <div class="separator"></div>
    <mat-button-toggle-group value="GESSEG" (valueChange)="screenChange($event)">
      <mat-button-toggle value="GESSEG">
        Gestión de la seguridad
      </mat-button-toggle>
      <mat-button-toggle value="GESBLO">
        Gestión de bloqueos
      </mat-button-toggle>
    </mat-button-toggle-group>
  </div>
  <div class="active-orders-table-container animated fadeIn" [ngClass]="{ hidden: displayedScreen != 'GESSEG' }">
    <mat-card class="override-elevation-z8">
      <mat-card-title style="padding: 15px 0;text-align: center;">Gestión de la seguridad</mat-card-title>
      <div class="active-orders-table-content-container">
        <div class="active-orders-table-actions-container">
          <mat-form-field appearance="outline" class="w-300p mr-8 ml-16">
            <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="separator"></div>
          <button mat-flat-button color="primary" class="override_no_shadow mr-10 animated fadeIn raised-button-background" (click)="openSecurityManagementForm('Registrar', null)">
            <mat-icon>add</mat-icon> Registrar gerencia de seguridad
          </button>
          <button mat-mini-fab class="orange_primary_background white_font override_no_shadow mr-10" matTooltip="Actualizar datos" (click)="getSecurityManagements()">
            <mat-icon>refresh</mat-icon>
          </button>
        </div>
        
        <div class="is-loading animated fadeIn fast" *ngIf="isLoadingSecMan">
          <mat-spinner align="center"></mat-spinner>
          <h3>Cargando datos ...</h3>
        </div>

        <div class="has-error animated fadeIn fast" *ngIf="!isLoadingSecMan && hasErrorSecMan">
          <mat-icon  class="red_primary_font">error</mat-icon>
          <h3>{{ errorStrSecMan }}</h3>
        </div>

        <div class="active-orders-table animated fadeIn" [ngClass]="{ hidden: isLoadingSecMan || hasErrorSecMan }">
          <table mat-table [dataSource]="dataSource!" matSort>
            <ng-container matColumnDef="ID">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>#</th>
              <td mat-cell *matCellDef="let row">Gerencia #{{ row.ID_GERENCIA_SEGURIDAD }}</td>
            </ng-container>
            
            <ng-container matColumnDef="GERENTE">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>Gerente</th>
              <td mat-cell *matCellDef="let row">{{ row.GERENTE }}</td>
            </ng-container>
            
            <ng-container matColumnDef="ORDENES">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>Órdenes relacionadas</th>
              <td mat-cell *matCellDef="let row">{{ row.NUMERO_ORDENES }}</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="ACCIONES">
              <th mat-header-cell *matHeaderCellDef>Acciones</th>
              <td mat-cell *matCellDef="let row">
                <button mat-mini-fab color="primary" matTooltip="Editar gerencia" class="override_no_shadow mr-4 white_font orange_primary_background" 
                *ngIf="!btnSmall"
                (click)="openSecurityManagementForm('Editar', row.ID_GERENCIA_SEGURIDAD)" [disabled]="row.ESTADO == 'Eliminado'">
                  <mat-icon>edit</mat-icon>
                </button>
                <button mat-mini-fab [ngClass]="{ pink_primary_background: row.ESTADO != 'Eliminado', white_font: row.ESTADO != 'Eliminado' }" 
                class="override_no_shadow mr-4" matTooltip="Ver detalles" 
                *ngIf="!btnSmall"
                (click)="openSecurityManagementDetails(row.ID_GERENCIA_SEGURIDAD)" 
                [disabled]="row.ESTADO == 'Eliminado'">
                  <mat-icon>visibility</mat-icon>
                </button>
                <button mat-mini-fab color="primary" class="override_no_shadow animated fadeIn gray_dark_font transparent_background" *ngIf="btnSmall" [matMenuTriggerFor]="menu">
                <mat-icon>more_vert</mat-icon>
              </button>
                <button mat-mini-fab color="warn" matTooltip="Eliminar gerencia" class="override_no_shadow red_primary_background white_font" 
                *ngIf="!btnSmall"                
                (click)="openDeleteConfirm(row.ID_GERENCIA_SEGURIDAD)" [disabled]="row.ESTADO == 'Eliminado'">
                  <mat-icon>delete</mat-icon>
                </button>

                <mat-menu #menu>
                  <button mat-menu-item (click)="openSecurityManagementForm('Editar', row.ID_GERENCIA_SEGURIDAD)">
                    <mat-icon>edit</mat-icon>
                    <span>Editar gerencia</span>
                  </button>

                  <button mat-menu-item (click)="openSecurityManagementDetails(row.ID_GERENCIA_SEGURIDAD)">
                    <mat-icon>visibility</mat-icon>
                    <span>Ver detalles</span>
                  </button>

                  <button mat-menu-item (click)="openDeleteConfirm(row.ID_GERENCIA_SEGURIDAD)">
                    <mat-icon>delete</mat-icon>
                    <span>Eliminar gerencia</span>
                  </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-80 centre" colspan="100%">
                <object data="assets/img/empty_data.svg" width="300"></object>
                <h2>Sin datos</h2>
              </td>
            </tr>
          </table>
        </div>

        <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator animated fadeIn" 
        [ngClass]="{ hidden: isLoadingSecMan || hasErrorSecMan }"></mat-paginator>
      </div>
    </mat-card>
  </div>
  <div class="active-orders-table-container animated fadeIn" [ngClass]="{ hidden: displayedScreen != 'GESBLO' }">
    <mat-card class="override-elevation-z8">
      <mat-card-title style="padding: 15px 0;text-align: center;">Gestión de bloqueos</mat-card-title>
      <div class="active-orders-table-content-container">
        <div class="active-orders-table-actions-container">
          <mat-form-field appearance="outline" class="w-300p mr-8 ml-16">
            <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="separator"></div>
          <button mat-flat-button color="primary" class="override_no_shadow mr-10 animated fadeIn" (click)="openBlockDialog()">
            <mat-icon>add</mat-icon> Añadir bloqueo
          </button>
          <button mat-mini-fab class="orange_primary_background white_font override_no_shadow mr-10" matTooltip="Actualizar datos" (click)="getBlockRegisters()">
            <mat-icon>refresh</mat-icon>
          </button>
        </div>
        
        <div class="is-loading animated fadeIn fast" *ngIf="isLoadingBlock">
          <mat-spinner align="center"></mat-spinner>
          <h3>Cargando datos ...</h3>
        </div>

        <div class="has-error animated fadeIn fast" *ngIf="!isLoadingBlock && hasErrorBlock">
          <mat-icon  class="red_primary_font">error</mat-icon>
          <h3>{{ errorStrBlock }}</h3>
        </div>

        <div class="active-orders-table animated fadeIn" [ngClass]="{ hidden: isLoadingBlock || hasErrorBlock }">
          <table mat-table [dataSource]="dataSourceBlock!" matSort #MatSort2="matSort">
            <ng-container matColumnDef="ID">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>#</th>
              <td mat-cell *matCellDef="let row">{{ row.ID_BLOQUEO }}</td>
            </ng-container>
            
            <ng-container matColumnDef="BLOQUEADO">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>Ente bloqueado</th>
              <td mat-cell *matCellDef="let row">{{ row.BLOQUEADO }}</td>
            </ng-container>
            
            <ng-container matColumnDef="TIPOBLOQUEO">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>Tipo del ente bloqueado</th>
              <td mat-cell *matCellDef="let row">{{ row.TIPO_BLOQUEADO }}</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="USRREG">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>Usuario última modificación</th>
              <td mat-cell *matCellDef="let row">{{ row.USUREG }}</td>
            </ng-container>
            
            <ng-container matColumnDef="FECREG">
              <th mat-header-cell *matHeaderCellDef mat-sort-header>Fecha última modificación</th>
              <td mat-cell *matCellDef="let row">{{ row.FECMOD == null ? row.FECREG : row.FECMOD }}</td>
            </ng-container>
            
            <ng-container matColumnDef="ACCIONES">
              <th mat-header-cell *matHeaderCellDef>Acciones</th>
              <td mat-cell *matCellDef="let row">
                <button mat-mini-fab [ngClass]="{ amber_primary_background: row.ESTADO == 'Activo', white_font: row.ESTADO == 'Activo' }" 
                class="override_no_shadow" matTooltip="Revocar bloqueo" (click)="confirmUnblock(row.ID_BLOQUEO)" [disabled]="row.ESTADO != 'Activo'">
                  <mat-icon>cancel</mat-icon>
                </button>
              </td>
            </ng-container>

            <tr mat-header-row *matHeaderRowDef="displayedColumnsBlock"></tr>
            <tr mat-row *matRowDef="let row; columns: displayedColumnsBlock"></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>

        <mat-paginator [pageSizeOptions]="[10, 50, 100]" class="override-paginator animated fadeIn" 
        [ngClass]="{ hidden: isLoadingBlock || hasErrorBlock }" #MatPaginator2="matPaginator"></mat-paginator>
      </div>
    </mat-card>
  </div>
</div>