<!--
Copyright 2017 The Kubernetes Authors.

Licensed 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.
-->

<kd-card [initialized]="initialized"
         role="table">
  <div title
       i18n>Endpoints</div>

  <div description>
    <div class="kd-inline-property"
         *ngIf="endpoints?.length">
      <span class="kd-muted-light"
            i18n>Items:&nbsp;</span>
      <span>{{endpoints.length}}</span>
    </div>
  </div>

  <div content
       [hidden]="endpoints?.length === 0">
    <mat-table [dataSource]="getDataSource()"
               [trackBy]="trackByEndpoint">
      <ng-container [matColumnDef]="getEndpointsColumns()[0]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Host</mat-header-cell>
        <mat-cell *matCellDef="let endpoint">
          <ng-container *ngIf="endpoint.host">{{endpoint.host}}</ng-container>
          <ng-container *ngIf="!endpoint.host">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getEndpointsColumns()[1]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Ports (Name, Port, Protocol)</mat-header-cell>
        <mat-cell *matCellDef="let endpoint">
          <ng-container *ngIf="endpoint?.ports">
            <div *ngFor="let port of endpoint.ports"
                 class="ports-item-line-height">
              <span *ngIf="port.name">{{port.name}},{{port.port}},{{port.protocol}}</span>
              <span *ngIf="!port.name">&lt;<span i18n>unset</span>&gt;,{{port.port}},{{port.protocol}}</span>
            </div>
          </ng-container>
          <ng-container *ngIf="!endpoint?.ports">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getEndpointsColumns()[2]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Node</mat-header-cell>
        <mat-cell *matCellDef="let endpoint">
          <ng-container *ngIf="endpoint.nodeName">
            {{endpoint.nodeName}}
          </ng-container>
          <ng-container *ngIf="!endpoint.nodeName">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getEndpointsColumns()[3]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Ready</mat-header-cell>
        <mat-cell *matCellDef="let endpoint">
          <ng-container *ngIf="endpoint.ready">
            {{endpoint.ready}}
          </ng-container>
          <ng-container *ngIf="!endpoint.ready">-</ng-container>
        </mat-cell>
      </ng-container>
      <mat-header-row *matHeaderRowDef="getEndpointsColumns()"></mat-header-row>
      <mat-row *matRowDef="let row; columns: getEndpointsColumns();"></mat-row>
    </mat-table>
  </div>

  <div content
       [hidden]="endpoints?.length != 0">
    <kd-list-zero-state></kd-list-zero-state>
  </div>
</kd-card>
