<main class="main-container animated fadeIn" (window:resize)="onResize()">
    <header id="navigation" class="btn-navigate mb-8">
        <div class="prev-page prevent-select indigo_primary_background
            mat-elevation-z8" matRipple [routerLink]="['/sam/GPRS']">
            <mat-icon style="color: white">arrow_back</mat-icon>
            <div class="page-name ml-4">Menú de Gestión del Personal</div>
        </div>
    </header>

    <mat-card class="override-card override-elevation-z8">

        <mat-tab-group style="overflow: auto;" #tabGroup
            (selectedTabChange)="tabChange($event)">
            <mat-tab label="Intervenciones">
                <section class="override-section">
                    <nav>
                        <mat-card-title class="mat-card-title centre">Lista de
                            Intervenciones</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)]="txtBuscadorInterventions"
                                    (keyup)="applyFilterInterventions($event,'INP')"
                                    placeholder="Ingrese la palabra a buscar" />
                                <mat-icon *ngIf="txtBuscadorInterventions.length
                                    === 0"
                                    matSuffix>search</mat-icon>
                                <mat-icon
                                    *ngIf="txtBuscadorInterventions.length> 0"
                                    class="clickable" matTooltip="Eliminar
                                    filtro"
                                    (click)="applyFilterInterventions('',
                                    'EST')" matSuffix>close</mat-icon>
                            </mat-form-field>
                            <div class="override-buttons">
                                <button mat-mini-fab color="info"
                                    (click)="getInterventions()"
                                    [disabled]="isLoading"
                                    matTooltip="Actualizar
                                    Datos" class="override-no-shadow mr-10">
                                    <mat-icon>refresh</mat-icon>
                                </button>
                            </div>
                        </div>
                    </nav>
                    <!-- ALERTAS - CARGANDO FORMULARIOS -->
                    <div>
                        <div class="is-loading animated fadeIn fast"
                            *ngIf="isLoading">
                            <mat-spinner align="center"></mat-spinner>
                            <h3>Cargando datos ...</h3>
                        </div>
                        <mat-progress-bar mode="indeterminate"
                            *ngIf="isLoadingForm"></mat-progress-bar>
                    </div>
                    <!-- CONTENEDOR DE LA TABLA -->
                    <div class="override-table" style="height: calc(100% -
                        66px)!important;">
                        <!-- TABLA  -->
                        <table mat-table [dataSource]="dataSourceInterventions!"
                            matSort
                            class="animated fadeIn" [style.display]="isLoading ?
                            'none' : 'revert'">
                            <ng-container matColumnDef="EQUIPMENTS_ID">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Equipo intervenido</th>
                                <td mat-cell *matCellDef="let element">{{
                                    element.EQUIPMENTS_ID.length > 0 ? element.EQUIPMENTS_ID : "-" }}</td>
                            </ng-container>
                            <ng-container matColumnDef="START_DATE">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Fecha
                                    de Inicio</th>
                                <td mat-cell *matCellDef="let element">
                                    {{element.START_DATE}}
                                </td>
                            </ng-container>
                            <ng-container matColumnDef="END_DATE">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Fecha de Término</th>
                                <td mat-cell *matCellDef="let element">
                                    {{element.END_DATE}}
                                </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"
                                        class="override-no-shadow mr-4"
                                        [disabled]="isLoadingForm"
                                        matTooltip="Ver Detalles"
                                        (click)="openDialog('DEI',
                                        element)">
                                        <mat-icon>visibility</mat-icon>
                                    </button>
                                </td>
                            </ng-container>

                            <tr mat-header-row
                                *matHeaderRowDef="displayedColumnsInterventions"></tr>
                            <tr mat-row *matRowDef="let row; columns:
                                displayedColumnsInterventions"></tr>
                            <tr class="mat-row" *matNoDataRow>
                                <td class="mat-cell p-80 centre" colspan="12">
                                    <object data="assets/img/empty_data.svg"
                                        width="300"></object>
                                    <h2>Sin datos</h2>
                                </td>
                            </tr>
                        </table>
                    </div>
                </section>

            </mat-tab>

            <mat-tab label="Contratos">

                <section class="override-section">
                    <nav>
                        <mat-card-title class="mat-card-title centre">Lista de
                            Contratos</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)]="txtBuscadorContracts"
                                    (keyup)="applyFilterContracts($event,'INP')"
                                    placeholder="Ingrese la palabra a buscar" />
                                <mat-icon *ngIf="txtBuscadorContracts.length ===
                                    0"
                                    matSuffix>search</mat-icon>
                                <mat-icon *ngIf="txtBuscadorContracts.length> 0"
                                    class="clickable" matTooltip="Eliminar
                                    filtro"
                                    (click)="applyFilterContracts('', 'EST')"
                                    matSuffix>close</mat-icon>
                            </mat-form-field>
                            <div class="override-buttons">
                                <button mat-raised-button color="primary"
                                    matTooltip="Registrar Formulario"
                                    [disabled]="isLoading" *ngIf="!btnSmall"
                                    class="override-no-shadow mr-10"
                                    (click)="openDialog('REG')">
                                    <mat-icon>add</mat-icon> Nuevo
                                </button>
                                <button mat-mini-fab color="info"
                                    (click)="getContracts()"
                                    [disabled]="isLoading"
                                    matTooltip="Actualizar
                                    Datos" class="override-no-shadow mr-10">
                                    <mat-icon>refresh</mat-icon>
                                </button>
                            </div>
                        </div>
                    </nav>
                    <!-- ALERTAS - CARGANDO FORMULARIOS -->
                    <div>
                        <div class="is-loading animated fadeIn fast"
                            *ngIf="isLoading">
                            <mat-spinner align="center"></mat-spinner>
                            <h3>Cargando datos ...</h3>
                        </div>
                        <mat-progress-bar mode="indeterminate"
                            *ngIf="isLoadingForm"></mat-progress-bar>
                    </div>
                    <!-- CONTENEDOR DE LA TABLA -->
                    <div class="override-table" style="height: calc(100% -
                        66px)!important;">
                        <!-- TABLA  -->
                        <table mat-table [dataSource]="dataSourceContracts!"
                            matSort #MatSort2="matSort"
                            class="animated fadeIn" [style.display]="isLoading ?
                            'none' : 'revert'">
                            <ng-container matColumnDef="CONTRACT_TYPE">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Tipo de Contrato</th>
                                <td mat-cell *matCellDef="let element">{{
                                    element.CONTRACT_TYPE }}</td>
                            </ng-container>
                            <ng-container matColumnDef="DENOMINATION">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Denominación
                                </th>
                                <td mat-cell *matCellDef="let element">{{
                                    element.DENOMINATION.length > 0 ?
                                    element.DENOMINATION : "-"}}</td>
                            </ng-container>
                            <ng-container matColumnDef="DURATION">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Duración
                                </th>
                                <td mat-cell *matCellDef="let element">{{
                                    element.DURATION }}</td>
                            </ng-container>
                            <ng-container matColumnDef="CONTRACT_COST">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Valor
                                </th>
                                <td mat-cell *matCellDef="let element">${{
                                    element.CONTRACT_COST }}</td>
                            </ng-container>
                            <ng-container matColumnDef="REGISTERED_BY">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Usuario que Registró
                                </th>
                                <td mat-cell *matCellDef="let element">{{
                                    element.REGISTERED_BY }}</td>
                            </ng-container>
                            <ng-container matColumnDef="REGISTER_DATE">
                                <th mat-header-cell *matHeaderCellDef
                                    mat-sort-header>Fecha de Registro
                                </th>
                                <td mat-cell *matCellDef="let element">{{
                                    element.REGISTER_DATE }}</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="accent"
                                        *ngIf="btnSmall"
                                        [disabled]="isLoading"
                                        [matMenuTriggerFor]="menu"
                                        #menuTrigger class="override-no-shadow">
                                        <mat-icon>settings</mat-icon>
                                    </button>
                                    <mat-menu #menu="matMenu">
                                        <button mat-menu-item
                                            (click)="openDialog('DEC',
                                            element)">
                                            <mat-icon>visibility</mat-icon>
                                            Detalles
                                        </button>
                                        <!-- Pendiente por modulo gestión de adquisiciónes -->
                                        <button mat-menu-item
                                            (click)="openDialog('DOW', element)">
                                            <mat-icon>download</mat-icon>
                                            Descargar
                                        </button>
                                    </mat-menu>

                                    <div *ngIf="!btnSmall">
                                        <button
                                            mat-mini-fab
                                            color="primary"
                                            class="override-no-shadow mr-4"
                                            [disabled]="isLoadingForm"
                                            matTooltip="Ver Historial"
                                            (click)="openDialog('DEC',
                                            element)">
                                            <mat-icon>visibility</mat-icon>
                                        </button>
                                        <!-- Pendiente por modulo gestión de adquisiciónes -->
                                        <button
                                            mat-mini-fab
                                            color="accent"
                                            class="override-no-shadow mr-4"
                                            [disabled]="isLoadingForm"
                                            (click)="openDialog('DOW', element)"
                                            matTooltip="Descargar Documento">
                                            <mat-icon>download</mat-icon>
                                        </button>
                                    </div>
                                </td>
                            </ng-container>

                            <tr mat-header-row
                                *matHeaderRowDef="displayedColumnsContracts"></tr>
                            <tr mat-row *matRowDef="let row; columns:
                                displayedColumnsContracts"></tr>
                            <tr class="mat-row" *matNoDataRow>
                                <td class="mat-cell p-80 centre" colspan="12">
                                    <object data="assets/img/empty_data.svg"
                                        width="300"></object>
                                    <h2>Sin datos</h2>
                                </td>
                            </tr>
                        </table>
                    </div>
                </section>

            </mat-tab>

        </mat-tab-group>
        <!-- PAGINADOR -->
        <mat-paginator [pageSizeOptions]="[10, 50, 100]"
            class="override-paginator" [style.display]="changeOnTab ?
            'none' : 'revert'"></mat-paginator>

        <mat-paginator [pageSizeOptions]="[10, 50, 100]"
            #MatPaginator2="matPaginator" class="override-paginator"
            [style.display]="!changeOnTab ?
            'none' : 'revert'"></mat-paginator>

    </mat-card>

</main>