<project-header class="top-header"></project-header>
  <project-page>

  <!-- Middle section -->
  <div class="middle-section">
    <div id="scrollable-content" class="middle-container has-scroll">
      <div class="middle-header">
        <div class="container-fluid">
          <breadcrumbs breadcrumbs="breadcrumbs"></breadcrumbs>
          <alerts alerts="alerts"></alerts>
          <div ng-if="!loaded">Loading...</div>
          <div ng-if="service">
            <h1>
              {{service.metadata.name}}
              <div class="pull-right dropdown">
                <button type="button" class="dropdown-toggle btn btn-default actions-dropdown-btn hidden-xs" data-toggle="dropdown">
                  Actions
                  <span class="caret"></span>
                </button>
                <a href=""
                   class="dropdown-toggle actions-dropdown-kebab visible-xs-inline"
                   data-toggle="dropdown"><i class="fa fa-ellipsis-v"></i><span class="sr-only">Actions</span></a>
                <ul class="dropdown-menu actions action-link">
                  <li>
                    <a ng-href="project/{{project.metadata.name}}/create-route?service={{service.metadata.name}}"
                       role="button">Create Route</a>
                  </li>
                  <li>
                    <edit-link
                      resource="service"
                      kind="Service"
                      alerts="alerts">
                    </edit-link>
                  </li>
                  <li>
                    <delete-link
                      kind="Service"
                      resource-name="{{service.metadata.name}}"
                      project-name="{{service.metadata.namespace}}"
                      alerts="alerts">
                    </delete-link>
                  </li>
                </ul>
              </div>
              <small class="meta">created <relative-timestamp timestamp="service.metadata.creationTimestamp"></relative-timestamp></small>
            </h1>
            <labels labels="service.metadata.labels" clickable="true" kind="services" project-name="{{service.metadata.namespace}}" limit="3"></labels>
          </div>
        </div>
      </div><!-- /middle-header-->
      <div class="middle-content">
        <div class="container-fluid">
          <div class="row" ng-if="service">
            <div class="col-md-12">
              <uib-tabset>
                <uib-tab active="selectedTab.details">
                  <uib-tab-heading>Details</uib-tab-heading>
                  <div class="resource-details">
                    <dl class="dl-horizontal left">
                      <dt>Selectors:</dt>
                      <dd>
                        <span ng-if="!service.spec.selector"><em>none</em></span>
                        <span ng-repeat="(selectorLabel, selectorValue) in service.spec.selector"> {{selectorLabel}}={{selectorValue}}<span ng-show="!$last">, </span></span>
                      </dd>
                      <dt>Type:</dt>
                      <dd>{{service.spec.type}}</dd>
                      <dt>IP:</dt>
                      <dd>{{service.spec.clusterIP}}</dd>
                      <dt>Session affinity:</dt>
                      <dd>{{service.spec.sessionAffinity}}</dd>
                      <dt ng-if="resource.status.loadBalancer.ingress.length">Ingress points</dt>
                      <dd ng-if="resource.status.loadBalancer.ingress.length">
                        <span ng-repeat="ingress in resource.status.loadBalancer.ingress"
                          >{{ingress.ip}}<span ng-if="!$last">, </span></span>
                      </dd>
                      <dt>Routes:</dt>
                      <dd>
                        <span ng-if="!routesForService.length">
                          <a ng-href="project/{{project.metadata.name}}/create-route?service={{service.metadata.name}}">Create route</a>
                        </span>
                        <span ng-repeat="route in routesForService">
                            <span ng-if="route | isWebRoute"><a ng-href="{{route | routeWebURL}}">{{route | routeLabel}}</a></span>
                            <span ng-if="!(route | isWebRoute)">{{route | routeLabel}}</span>
                            <span ng-show="!$last">, </span>
                        </span>
                      </dd>
                    </dl>
                    <div ng-if="service.spec.ports.length" class="table-responsive">
                      <table class="table table-bordered small service-table">
                        <thead>
                          <tr>
                            <th>Node Port</th>
                            <th role="presentation"></th>
                            <th>Service Port</th>
                            <th role="presentation"></th>
                            <th>Target Port</th>
                          </tr>
                        </thead>
                        <tbody>
                          <tr ng-repeat="portMapping in service.spec.ports | orderBy:'port'">
                            <td>
                              <span ng-if="portMapping.nodePort">{{portMapping.nodePort}}</span>
                              <span ng-if="!portMapping.nodePort" class="text-muted">none</span>
                            </td>
                            <td role="presentation" class="text-muted">&#8594;</td>
                            <td>{{portMapping.port}}/{{portMapping.protocol}}
                                <span ng-if="portMapping.name">({{portMapping.name}})</span></td>
                            <td role="presentation" class="text-muted">&#8594;</td>
                            <td>{{portMapping.targetPort}}</td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                    <annotations annotations="service.metadata.annotations"></annotations>
                  </div>
                </uib-tab>
                <uib-tab active="selectedTab.events">
                  <uib-tab-heading>Events</uib-tab-heading>
                  <events resource-kind="Service" resource-name="{{service.metadata.name}}" project-context="projectContext" ng-if="selectedTab.events"></events>
                </uib-tab>
              </uib-tabset>
            </div><!-- /col-* -->
          </div>
        </div>
      </div><!-- /middle-content -->
    </div><!-- /middle-container -->
  </div><!-- /middle-section -->
  </project-page>
