<!--
  ~  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="system-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>

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

                            <!-- Processor Load Average column -->
                            <ng-container matColumnDef="processorLoadAverage">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Core Load Average">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">
                                        Core Load Average
                                    </div>
                                </th>
                                <td
                                    mat-cell
                                    *matCellDef="let item"
                                    [title]="formatFloat(item.snapshot.processorLoadAverage)">
                                    {{ formatFloat(item.snapshot.processorLoadAverage) }}
                                </td>
                            </ng-container>

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

                            <!-- Daemon Threads column -->
                            <ng-container matColumnDef="daemonThreads">
                                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Daemon Threads">
                                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">
                                        Daemon Threads
                                    </div>
                                </th>
                                <td mat-cell *matCellDef="let item" [title]="item.snapshot.daemonThreads">
                                    {{ item.snapshot.daemonThreads }}
                                </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>
