<!--
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">
  <div description>
    <span class="kd-muted-light"
          i18n>Image:&nbsp;</span>{{container.image}}
  </div>
  <div title>
    <mat-icon *ngIf="container.status"
              class="container-status-icon"
              [ngClass]="containerStatusClass"
              [matTooltip]="containerStatus">fiber_manual_record</mat-icon>
    {{container.name}}
  </div>
  <div content
       fxFlex
       fxLayout="row wrap">
    <kd-property fxFlex="100">
      <div key
           i18n>Image
      </div>
      <div value>{{container.image}}</div>
    </kd-property>

    <div *ngIf="container.status?.state"
         class="kd-muted section-header"
         fxFlex="100"
         i18n>Status</div>

    <ng-container *ngIf="container.status">
      <kd-property>
        <div key
             i18n>Ready
        </div>
        <div value>{{container.status.ready}}</div>
      </kd-property>

      <kd-property>
        <div key
             i18n>Started
        </div>
        <div value>{{container.status.started}}</div>
      </kd-property>
    </ng-container>

    <ng-container *ngIf="container.status?.state?.waiting">
      <kd-property *ngIf="container.status.state.waiting.reason">
        <div key
             i18n>Reason
        </div>
        <div value>{{container.status.state.waiting.reason}}</div>
      </kd-property>

      <kd-property *ngIf="container.status.state.waiting.message">
        <div key
             i18n>Message
        </div>
        <div value>{{container.status.state.waiting.message}}</div>
      </kd-property>
    </ng-container>

    <ng-container *ngIf="container.status?.state?.terminated">
      <kd-property *ngIf="container.status.state.terminated.reason">
        <div key
             i18n>Reason
        </div>
        <div value>{{container.status.state.terminated.reason}}</div>
      </kd-property>

      <kd-property *ngIf="container.status.state.terminated.message">
        <div key
             i18n>Message
        </div>
        <div value>{{container.status.state.terminated.message}}</div>
      </kd-property>

      <kd-property *ngIf="container.status.state.terminated.exitCode">
        <div key
             i18n>Exit Code
        </div>
        <div value>{{container.status.state.terminated.exitCode}}</div>
      </kd-property>

      <kd-property *ngIf="container.status.state.terminated.signal">
        <div key
             i18n>Signal
        </div>
        <div value>{{container.status.state.terminated.signal}}</div>
      </kd-property>
    </ng-container>

    <ng-container *ngIf="container.status?.state?.running">
      <kd-property *ngIf="container.status.state.running.startedAt">
        <div key
             i18n>Started At
        </div>
        <div value>{{container.status.state.running.startedAt}}</div>
      </kd-property>
    </ng-container>

    <div *ngIf="container?.env?.length > 0"
         class="kd-muted section-header"
         fxFlex="100"
         i18n>Environment Variables</div>

    <div *ngFor="let env of container?.env;trackBy:getEnvVarID">
      <ng-container *ngIf="!isSecret(env) && !isConfigMap(env)">
        <kd-property>
          <div key
               fxLayout>
            {{env.name}}
            <mat-icon matTooltip="Environment variable"
                      i18n-matTooltip
                      class="kd-env-variable-icon">public
            </mat-icon>
          </div>
          <div value>{{env.value || '-'}}</div>
        </kd-property>
      </ng-container>

      <ng-container *ngIf="isSecret(env)">
        <kd-hidden-property>
          <div key
               fxLayout>
            <a [routerLink]="getEnvSecretHref(env.valueFrom.secretKeyRef)"
               queryParamsHandling="preserve"
               (click)="$event.stopPropagation()">
              {{env.name}}
            </a>
            <mat-icon matTooltip="Environment variable"
                      i18n-matTooltip
                      class="kd-env-variable-icon">public
            </mat-icon>
          </div>
          <div whenVisible
               class="kd-code-block">{{formatSecretValue(env.value)}}</div>
          <div whenHidden
               i18n>{{formatSecretValue(env.value).length}} bytes
          </div>
        </kd-hidden-property>
      </ng-container>

      <ng-container *ngIf="isConfigMap(env)">
        <kd-hidden-property>
          <div key
               fxLayout>
            <a [routerLink]="getEnvConfigMapHref(env.valueFrom.configMapKeyRef)"
               queryParamsHandling="preserve"
               (click)="$event.stopPropagation()">
              {{env.name}}
            </a>
            <mat-icon matTooltip="Environment variable"
                      i18n-matTooltip
                      class="kd-env-variable-icon">public
            </mat-icon>
          </div>
          <div whenVisible
               class="kd-code-block">{{env.value}}</div>
          <div whenHidden
               i18n>{{env.value.length}} bytes
          </div>
        </kd-hidden-property>
      </ng-container>
    </div>

    <kd-property *ngIf="container?.commands?.length"
                 fxFlex="100">
      <div key
           fxFlex
           class="kd-muted section-header"
           i18n>Commands
      </div>
      <div value>
        <div class="kd-code-block kd-no-whitespace">
          <div *ngFor="let command of container.commands"
               class="kd-code-block-font">{{command}}</div>
        </div>
      </div>
    </kd-property>

    <kd-property *ngIf="container?.args?.length"
                 fxFlex="100">
      <div key
           fxFlex
           class="kd-muted section-header"
           i18n>Arguments
      </div>
      <div value>
        <div class="kd-code-block kd-no-whitespace">
          <div *ngFor="let arg of container.args"
               class="kd-code-block-font">{{arg}}</div>
        </div>
      </div>
    </kd-property>

    <kd-property *ngIf="container?.volumeMounts?.length > 0"
                 [stretched]="true"
                 fxFlex="100">
      <div key
           fxFlex
           class="kd-muted section-header"
           i18n>Mounts
      </div>
      <div value
           class="kd-volume-mounts">
        <kd-volumemounts-list [volumeMounts]="container?.volumeMounts"
                              [namespace]="namespace"
                              [initialized]="initialized">
        </kd-volumemounts-list>
      </div>
    </kd-property>

    <div *ngIf="hasSecurityContext()"
         fxFlex="100"
         fxLayout="column">
      <div fxFlex
           class="kd-muted section-header"
           i18n>Security Context
      </div>

      <kd-security-context [securityContext]="container.securityContext"
                           [initialized]="initialized">
      </kd-security-context>
    </div>


    <div *ngIf="container?.livenessProbe"
         fxFlex="100"
         fxLayout="column">
      <div fxFlex
           class="kd-muted section-header"
           i18n>Liveness Probe
      </div>
      <kd-probe-card [probe]="container?.livenessProbe"
                     [initialized]="initialized">
      </kd-probe-card>
    </div>

    <div *ngIf="container?.readinessProbe"
         fxFlex="100"
         fxLayout="column">
      <div fxFlex
           class="kd-muted section-header"
           i18n>Readiness Probe
      </div>
      <kd-probe-card [probe]="container?.readinessProbe"
                     [initialized]="initialized">
      </kd-probe-card>
    </div>

    <div *ngIf="container?.startupProbe"
         fxFlex="100"
         fxLayout="column">
      <div fxFlex
           class="kd-muted section-header"
           i18n>Startup Probe
      </div>
      <kd-probe-card [probe]="container?.startupProbe"
                     [initialized]="initialized">
      </kd-probe-card>
    </div>

  </div>

  <div content>
  </div>

</kd-card>
