<!--
  Expects the following variables:
  podTemplate
  imagesByDockerReference (optional)
  builds (optional)
 -->
<div class="pod-template-container">
  <div class="pod-template-block" ng-repeat="container in podTemplate.spec.containers">
    <div class="pod-template">
      <div class="component-label">Container: {{container.name}}</div>
      <div row ng-if="container.image" class="pod-template-image icon-row">
        <div>
          <span class="pficon pficon-image" aria-hidden="true"></span> 
        </div>
        <div flex>
          Image: 
          <span ng-if="!imagesByDockerReference[container.image]">{{container.image | imageStreamName}}</span>
          <span ng-if="imagesByDockerReference[container.image]">
            <a ng-href="{{imagesByDockerReference[container.image].imageStreamName | navigateResourceURL : 'ImageStream' : imagesByDockerReference[container.image].imageStreamNamespace}}">{{container.image | imageStreamName}}</a>
            (<span title="{{imagesByDockerReference[container.image].metadata.name}}">{{imagesByDockerReference[container.image].metadata.name | stripSHAPrefix | limitTo: 7}}</span>)
          </span>
        </div>
      </div>
      <div ng-if="imagesByDockerReference && container.image && (image = imagesByDockerReference[container.image])" class="pod-template-build">
        <div row class="icon-row" ng-if="build = (image | buildForImage : builds)">
          <div>
            <span class="fa fa-refresh" aria-hidden="true"></span>
          </div> 
          <div flex>Build:
            <a ng-href="{{build | navigateResourceURL}}">
              <span ng-if="(build | annotation : 'buildNumber')">#{{build | annotation : 'buildNumber'}}</span>
              <span ng-if="!(build | annotation : 'buildNumber')">{{build.metadata.name}}</span>
            </a>
            <span ng-if="build.spec.source">
              from
              <span class="fa fa-code" aria-hidden="true"></span>
              <span>
                <span ng-switch="build.spec.source.type">
                  <span ng-switch-when="Git">
                    <span ng-if="build.spec.revision.git.commit">
                      {{build.spec.revision.git.message}}
                      (<osc-git-link
                        uri="build.spec.source.git.uri"
                        commit="build.spec.revision.git.commit">{{build.spec.revision.git.commit | limitTo:7}}</osc-git-link>)
                      <span ng-if="build.spec.revision.git.author">
                        authored by {{build.spec.revision.git.author.name}}
                      </span>
                    </span>
                    <span ng-if="!build.spec.revision.git.commit">
                      <osc-git-link uri="build.spec.source.git.uri">{{build.spec.source.git.uri}}</osc-git-link>
                    </span>
                  </span>
                  <span ng-switch-default>
                    {{build.spec.source.type || 'Unknown'}}
                  </span>
                </span>
              </span>
            </span>
          </div>         
        </div>
      </div>

      <div row ng-if="container.ports.length > 0" class="pod-template-ports icon-row">
        <div>
          <span data-icon="" aria-hidden="true" style="font-size:16px;line-height:normal"></span>
        </div>
        <div flex>
          Ports:
          <span ng-repeat="port in container.ports | orderBy: 'containerPort'">
            <span class="nowrap">{{port.containerPort}}/{{port.protocol}}<span ng-if="port.name">&thinsp;({{port.name}})</span><span ng-if="port.hostPort">&thinsp;<span class="port-icon">&#8594;</span>&thinsp;{{port.hostPort}}</span></span><span ng-if="!$last">, </span>
          </span>
        </div>
      </div> 

      <div row ng-if="detailed" ng-repeat="mount in container.volumeMounts" class="icon-row">
        <div>
          <span aria-hidden="true" class="fa fa-database"></span>
        </div>
        <div flex>
          Mount:
          <span>
            {{mount.name}}&#8201;&#8594;&#8201;{{mount.mountPath}}
          </span>
        </div>
      </div>

      <div hawtio-extension name="container-links"></div>

    </div>
  </div>
</div>
