<!--
  ~ 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="remote-process-group-cluster-table relative h-full">
    <div class="listing-table absolute inset-0 overflow-y-auto">
        <table
            mat-table
            [dataSource]="dataSource"
            matSort
            matSortDisableClear
            (matSortChange)="sortData($event)"
            [matSortActive]="initialSortColumn"
            [matSortDirection]="initialSortDirection">
            <!-- Node Column -->
            <ng-container matColumnDef="node">
                <th mat-header-cell *matHeaderCellDef mat-sort-header>
                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Node</div>
                </th>
                <td mat-cell *matCellDef="let item" [title]="formatNode(item)">
                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">{{ formatNode(item) }}</div>
                </td>
            </ng-container>

            <!-- Target URI Column -->
            <ng-container matColumnDef="uri">
                <th mat-header-cell *matHeaderCellDef mat-sort-header>
                    <div class="overflow-ellipsis overflow-hidden whitespace-nowrap">Target URI</div>
                </th>
                <td mat-cell *matCellDef="let item" [title]="formatUri(item)">
                    {{ formatUri(item) }}
                </td>
            </ng-container>

            <!-- Transmission Status column -->
            <ng-container matColumnDef="transmitting">
                <th mat-header-cell *matHeaderCellDef mat-sort-header>Transmitting</th>
                <td mat-cell *matCellDef="let item">
                    <div
                        class="inline-block overflow-hidden overflow-ellipsis whitespace-nowrap space-x-1.5 align-middle">
                        <span [ngClass]="getTransmissionStatusIcon(item)"></span>
                        <span [title]="formatTransmitting(item)">{{ formatTransmitting(item) }}</span>
                        @if (item.activeThreadCount > 0) {
                            <span title="Active Threads">({{ item.activeThreadCount }})</span>
                        }
                    </div>
                </td>
            </ng-container>

            <!-- Sent column -->
            <ng-container matColumnDef="sent">
                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Count / data size in the last 5 minutes">
                    <div class="inline-block overflow-hidden overflow-ellipsis whitespace-nowrap space-x-1">
                        <span [ngClass]="{ underline: multiSort.active === 'sent' && multiSort.sortValueIndex === 0 }"
                            >Sent</span
                        >
                        <span [ngClass]="{ underline: multiSort.active === 'sent' && multiSort.sortValueIndex === 1 }"
                            >(Size)</span
                        >
                        <span class="font-light">5 min</span>
                    </div>
                </th>
                <td mat-cell *matCellDef="let item" [title]="formatSent(item)">
                    {{ formatSent(item) }}
                </td>
            </ng-container>

            <!-- Received column -->
            <ng-container matColumnDef="received">
                <th mat-header-cell *matHeaderCellDef mat-sort-header title="Count / data size in the last 5 minutes">
                    <div class="inline-block overflow-hidden overflow-ellipsis whitespace-nowrap space-x-1">
                        <span
                            [ngClass]="{ underline: multiSort.active === 'received' && multiSort.sortValueIndex === 0 }"
                            >Received</span
                        >
                        <span
                            [ngClass]="{ underline: multiSort.active === 'received' && multiSort.sortValueIndex === 1 }"
                            >(Size)</span
                        >
                        <span class="font-light">5 min</span>
                    </div>
                </th>
                <td mat-cell *matCellDef="let item" [title]="formatReceived(item)">
                    {{ formatReceived(item) }}
                </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>
