<!--
  ~  Licensed to the Apache Software Foundation (ASF) under one or more
  ~  contributor license agreements.  See the NOTICE file distributed with
  ~  this work for additional information regarding copyright ownership.
  ~  The ASF licenses this file to You under the Apache License, Version 2.0
  ~  (the "License"); you may not use this file except in compliance with
  ~  the License.  You may obtain a copy of the License at
  ~
  ~     http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing, software
  ~  distributed under the License is distributed on an "AS IS" BASIS,
  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~  See the License for the specific language governing permissions and
  ~  limitations under the License.
  -->
<div class="flex flex-col h-full gap-y-2">
    <div class="flex-1">
        <ng-container>
            <div class="jvm-node-table h-full flex flex-col">
                <!-- allow filtering of the table -->
                <cluster-table-filter
                    [filteredCount]="filteredCount"
                    [totalCount]="totalCount"
                    [filterableColumns]="filterableColumns"
                    filterColumn="address"
                    (filterChanged)="applyFilter($event)"></cluster-table-filter>

                <div class="flex-1 relative">
                    <div class="listing-table overflow-y-auto absolute inset-0">
                        <table
                            mat-table
                            [dataSource]="dataSource"
                            matSort
                            matSortDisableClear
                            (matSortChange)="sortData($event)"
                            [matSortActive]="initialSortColumn"
                            [matSortDirection]="initialSortDirection">
                            <!-- Node Address -->
                            <ng-container matColumnDef="address">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Node Address">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Node Address</div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="formatNodeAddress(item)">
                                    {{ formatNodeAddress(item) }}
                                </td>
                            </ng-container>

                            <!-- Max Heap -->
                            <ng-container matColumnDef="maxHeap">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Heap Max">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Heap Max</div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.maxHeap">
                                    {{ item.snapshot.maxHeap }}
                                </td>
                            </ng-container>

                            <!-- Total Heap -->
                            <ng-container matColumnDef="totalHeap">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Heap Total">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Heap Total</div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.totalHeap">
                                    {{ item.snapshot.totalHeap }}
                                </td>
                            </ng-container>

                            <!-- Used Heap -->
                            <ng-container matColumnDef="usedHeap">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Head Used">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Heap Used</div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.usedHeap">
                                    {{ item.snapshot.usedHeap }}
                                </td>
                            </ng-container>

                            <!-- Heap Utilization -->
                            <ng-container matColumnDef="heapUtilization">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Heap Utilization">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">
                                        Heap Utilization
                                    </div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.heapUtilization">
                                    {{ item.snapshot.heapUtilization }}
                                </td>
                            </ng-container>

                            <!-- Total Non Heap -->
                            <ng-container matColumnDef="totalNonHeap">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Non-Heap Total">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">
                                        Non-Heap Total
                                    </div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.totalNonHeap">
                                    {{ item.snapshot.totalNonHeap }}
                                </td>
                            </ng-container>

                            <!-- Used Heap -->
                            <ng-container matColumnDef="usedNonHeap">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Non-Heap Used">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Non-Heap Used</div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.usedNonHeap">
                                    {{ item.snapshot.usedNonHeap }}
                                </td>
                            </ng-container>

                            <!-- Garbage Collection -->
                            <ng-container matColumnDef="garbageCollection">
                                <th mat-header-cell *matHeaderCellDef title="Garbage Collection">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">GC</div>
                                </th>
                                <td mat-cell *matCellDef="let item">
                                    <div
                                        class="fa fa-info-circle"
                                        nifiTooltip
                                        [delayClose]="false"
                                        [position]="getGcTooltipPosition()"
                                        [tooltipComponentType]="GarbageCollectionTipComponent"
                                        [tooltipInputData]="getGarbageCollectionTipData(item)"></div>
                                </td>
                            </ng-container>

                            <!-- Uptime -->
                            <ng-container matColumnDef="uptime">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Uptime">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Uptime</div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.uptime">
                                    {{ item.snapshot.uptime }}
                                </td>
                            </ng-container>
                            <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
                            <tr
                                mat-row
                                *matRowDef="let row; let even = even; columns: displayedColumns"
                                [class.even]="even"
                                (click)="select(row)"
                                [class.selected]="isSelected(row)"></tr>
                        </table>
                    </div>
                </div>
            </div>
        </ng-container>
    </div>
</div>
