<!--
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>Rules</div>

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

  <div content
       [hidden]="!rules">
    <mat-table [dataSource]="getDataSource()">
      <ng-container [matColumnDef]="getRuleColumns()[0]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Resources</mat-header-cell>
        <mat-cell *matCellDef="let rule">
          <ng-container *ngIf="rule.resources">
            <span>
              {{ rule.resources | commaSeparated }}
            </span>
          </ng-container>
          <ng-container *ngIf="!rule.resources">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getRuleColumns()[1]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Non-resource URL</mat-header-cell>
        <mat-cell *matCellDef="let rule">
          <ng-container *ngIf="rule.nonResourceURLs">
            <span>
              {{ rule.nonResourceURLs | commaSeparated }}
            </span>
          </ng-container>
          <ng-container *ngIf="!rule.nonResourceURLs">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getRuleColumns()[2]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Resource Names</mat-header-cell>
        <mat-cell *matCellDef="let rule">
          <ng-container *ngIf="rule.resourceNames">
            <span>
              {{ rule.resourceNames | commaSeparated }}
            </span>
          </ng-container>
          <ng-container *ngIf="!rule.resourceNames">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getRuleColumns()[3]">
        <mat-header-cell *matHeaderCellDef
                         i18n>Verbs</mat-header-cell>
        <mat-cell *matCellDef="let rule">
          <ng-container *ngIf="rule.verbs">
            <span>
              {{ rule.verbs | commaSeparated }}
            </span>
          </ng-container>
          <ng-container *ngIf="!rule.verbs">-</ng-container>
        </mat-cell>
      </ng-container>
      <ng-container [matColumnDef]="getRuleColumns()[4]">
        <mat-header-cell *matHeaderCellDef
                         i18n>API Groups</mat-header-cell>
        <mat-cell *matCellDef="let rule">
          <ng-container *ngIf="rule.apiGroups && rule.apiGroups.length > 0">
            <span>
              {{ rule.apiGroups | commaSeparated }}
            </span>
          </ng-container>
          <ng-container *ngIf="!rule.apiGroups || rule.apiGroups.length === 0">-</ng-container>
        </mat-cell>
      </ng-container>
      <mat-header-row *matHeaderRowDef="getRuleColumns()"></mat-header-row>
      <mat-row *matRowDef="let row; columns: getRuleColumns();"></mat-row>
    </mat-table>
  </div>

  <div content
       [hidden]="rules">
    <kd-list-zero-state></kd-list-zero-state>
  </div>
</kd-card>
