<!--
  ~ 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.
  -->

<nz-table
  nzSize="small"
  [nzLoading]="isLoading"
  [nzData]="listOfTaskManager"
  [nzScroll]="{ x: '1550px', y: 'calc( 100% - 36px )' }"
  [nzFrontPagination]="false"
  [nzShowPagination]="false"
  [nzVirtualItemSize]="virtualItemSize"
  [nzVirtualMinBufferPx]="300"
  [nzVirtualMaxBufferPx]="300"
  [nzVirtualForTrackBy]="trackByEndpoint"
>
  <thead>
    <tr>
      <th nzWidth="160px" nzLeft [nzSortFn]="sortEndpointFn">Endpoint</th>
      <th nzWidth="150px" [nzSortFn]="sortReadBytesFn">Bytes received</th>
      <th nzWidth="150px" [nzSortFn]="sortReadRecordsFn">Records received</th>
      <th nzWidth="120px" [nzSortFn]="sortWriteBytesFn">Bytes sent</th>
      <th nzWidth="150px" [nzSortFn]="sortWriteRecordsFn">Records sent</th>
      <th nzWidth="200px" [nzSortFn]="sortStartTimeFn">Start Time</th>
      <th nzWidth="200px" [nzSortFn]="sortEndTimeFn">End Time</th>
      <th nzWidth="150px" [nzSortFn]="sortDurationFn">Duration</th>
      <th nzWidth="120px">Tasks</th>
      <th nzWidth="100px" nzRight [nzSortFn]="sortStatusFn">Status</th>
      <th nzWidth="50px" nzRight>More</th>
    </tr>
  </thead>
  <tbody>
    <ng-template nz-virtual-scroll let-data>
      <ng-container *ngIf="narrowLogData(data) as taskManager">
        <tr>
          <td nzLeft>
            <span class="ellipsis-cell">{{ taskManager.endpoint }}</span>
          </td>
          <td>
            <span *ngIf="taskManager['metrics']['read-bytes-complete']; else loadingTemplate">
              {{ taskManager['metrics']['read-bytes'] | humanizeBytes }}
            </span>
          </td>
          <td>
            <span *ngIf="taskManager['metrics']['read-records-complete']; else loadingTemplate">
              {{ taskManager['metrics']['read-records'] | number }}
            </span>
          </td>
          <td>
            <span *ngIf="taskManager['metrics']['write-bytes-complete']; else loadingTemplate">
              {{ taskManager['metrics']['write-bytes'] | humanizeBytes }}
            </span>
          </td>
          <td>
            <span *ngIf="taskManager['metrics']['write-records-complete']; else loadingTemplate">
              {{ taskManager['metrics']['write-records'] | number }}
            </span>
          </td>
          <td>{{ taskManager['start-time'] | humanizeDate: 'yyyy-MM-dd HH:mm:ss.SSS' }}</td>
          <td>{{ taskManager['end-time'] | humanizeDate: 'yyyy-MM-dd HH:mm:ss.SSS' }}</td>
          <td>{{ taskManager['duration'] | humanizeDuration }}</td>
          <td>
            <flink-dynamic-host
              [data]="{ tasks: taskManager['status-counts'] }"
              [component]="taskCountBadgeComponent"
            ></flink-dynamic-host>
          </td>
          <td nzRight>
            <flink-dynamic-host
              [data]="{ state: taskManager['status'] }"
              [component]="stateBadgeComponent"
            ></flink-dynamic-host>
          </td>
          <td nzRight>
            <flink-dynamic-host
              [data]="{ taskManager }"
              [component]="actionComponent"
            ></flink-dynamic-host>
          </td>
        </tr>
      </ng-container>
    </ng-template>
  </tbody>
</nz-table>
<ng-template #loadingTemplate>
  <i nz-icon nzType="loading"></i>
</ng-template>
