{{!
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
}}

{{breadcrumb-bar breadcrumbs=breadcrumbs}}

{{#if actionResponse}}
  <div class="alert-wrapper">
    <div class="col-md-12">
      <div class="alert alert-dismissible {{if (eq actionResponse.type 'error') 'alert-danger' 'alert-success'}}" role="alert">
        <button class="close" data-dismiss="alert" aria-label="Close" {{action "resetActionResponse"}}><span aria-hidden="true">&times;</span></button>
        <strong>{{actionResponse.msg}}</strong>
      </div>
    </div>
  </div>
{{/if}}

<div class="panel-group col-md-12">
  <div class="panel panel-default">
    <div class="yarn-app-header">
      <div class="flex">
        <div>
          <div class="flex">
            <div>
              <h3 class="yarn-app-name">
                {{#if model.app.unmanagedApplication}}
                  <span title="This is an unmanaged application" class="yarn-tooltip">
                    <i class="glyphicon glyphicon-exclamation-sign glyphicon-gray" />
                  </span>
                {{/if}}
                {{model.app.appName}}
              </h3>
            </div>
            {{#if model.app.finalStatus}}
            <div title="Final status" class="yarn-tooltip yarn-app-final-status offset-1">
              <span class={{model.app.finalStatusStyle}}>
                {{model.app.finalStatus}}
              </span>
            </div>
            {{/if}}
          </div>
          <div title="Application id" class="muted-text">{{model.app.id}}</div>
          {{em-table-simple-status-cell content=model.app.state}}
          <div class="flex">
            <div class="tail-2">
              <i class="glyphicon glyphicon-user glyphicon-gray" /> {{model.app.user}}
            </div>
            {{#if model.app.hasFinishedTime}}
              <div title="Started at {{model.app.formattedStartTime}}. &#10; Ran for {{model.app.formattedElapsedTime}}" class="yarn-tooltip">
                <i class="glyphicon glyphicon-time glyphicon-gray" />
                Finished at {{model.app.formattedFinishedTime}}
              </div>
            {{else}}
              <div title="Running for {{model.app.formattedElapsedTime}}" class="yarn-tooltip">
                <i class="glyphicon glyphicon-time glyphicon-gray" />
                Started at {{model.app.formattedStartTime}}
              </div>
            {{/if}}
          </div>
        </div>

        <div class="flex-right">
          <div class="links">
              {{#if (or (or isServiceDeployedOrRunning isServiceStoppped) isAppKillable)}}
              <div class="btn-group">
                <button type="button" class="btn btn-unstyled dropdown-toggle" title="Settings"
                  data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="margin-left: -5px;">
                  <i class="glyphicon glyphicon-cog"/> Settings
                </button>
                <ul class="dropdown-menu dropdown-menu-right">
                  {{#if isServiceDeployedOrRunning}}
                    <li>
                      <a href="#"  {{action "showStopServiceConfirm"}} target="_blank">
                        <i class="glyphicon glyphicon-stop" /> &nbsp;Stop Service
                      </a>
                    </li>
                    <li>
                      <a href="#" target="_blank" {{action "showDeleteServiceConfirm"}}>
                        <i class="glyphicon glyphicon-trash" /> &nbsp;Delete Service
                      </a>
                    </li>
                  {{/if}}
                  {{#if isServiceStoppped}}
                  <li>
                    <a href="#" target="_blank" {{action "showDeleteServiceConfirm"}}>
                      <i class="glyphicon glyphicon-trash" /> &nbsp;Delete Service
                    </a>
                  </li>
                  {{/if}}
                  {{#if isAppKillable}}
                    <li>
                      <a href="#"  {{action "showKillApplicationConfirm"}} target="_blank">
                        <i class="glyphicon glyphicon-stop" />&nbsp;Kill Application
                      </a>
                    </li>
                  {{/if}}
                </ul>
              </div>
            {{/if}}

            {{#if model.serviceName}}
              {{#if model.quicklinks}}
              <div class="btn-group quick-links">
                <button type="button" class="btn btn-unstyled dropdown-toggle" title="Quick links" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  <i class="glyphicon glyphicon-option-vertical" /> Quicklinks
                </button>
                <ul class="dropdown-menu dropdown-menu-right">
                  {{#each model.quicklinks as |link|}}
                    <li><a href="{{link.value}}" target="_blank">{{link.name}}</a></li>
                  {{/each}}
                </ul>
              </div>
              {{/if}}
            {{/if}}
          </div>
          <div class="btn-group">
            <span title="Queue" class="yarn-tooltip">
              <i class="glyphicon glyphicon-tasks glyphicon-gray" /> {{model.app.queue}}
            </span>
          </div>
          <div>Priority: {{model.app.priority}}</div>
          {{#if model.app.trackingUrl}}
            <div><a href="{{model.app.trackingUrl}}" target="_blank">{{model.app.trackingUI}}</a></div>
          {{/if}}
        </div>
      </div>
    </div>
    <div class="panel-heading">
      <div class="clearfix">
        <ul class="nav nav-pills">
          <ul class="nav nav-pills collapse in">
            {{#if model.serviceName}}
              {{#link-to 'yarn-app.components' tagName="li" class=(if (eq target.currentPath 'yarn-app.components') "active")}}
                {{#link-to 'yarn-app.components' appId (query-params service=model.serviceName)}}Components{{/link-to}}
              {{/link-to}}
              {{#link-to 'yarn-app.configs' tagName="li" class=(if (eq target.currentPath 'yarn-app.configs') "active")}}
                {{#link-to 'yarn-app.configs' appId (query-params service=model.serviceName)}}Configurations &amp; Metrics{{/link-to}}
              {{/link-to}}
            {{/if}}
            {{#link-to 'yarn-app.attempts' tagName="li" class=(if (eq target.currentPath 'yarn-app.attempts') "active")}}
              {{#link-to 'yarn-app.attempts' appId (query-params service=model.serviceName)}}Attempts List{{/link-to}}
            {{/link-to}}
            {{#link-to 'yarn-app.charts' tagName="li" class=(if (eq target.currentPath 'yarn-app.charts') "active")}}
              {{#link-to 'yarn-app.charts' appId (query-params service=model.serviceName)}}Resource Usage{{/link-to}}
            {{/link-to}}
            {{#link-to 'yarn-app.info' tagName="li" class=(if (eq target.currentPath 'yarn-app.info') "active")}}
              {{#link-to 'yarn-app.info' appId (query-params service=model.serviceName)}}Diagnostics{{/link-to}}
            {{/link-to}}
            {{#link-to 'yarn-app.logs' tagName="li" class=(if (eq target.currentPath 'yarn-app.logs') "active")}}
              {{#link-to 'yarn-app.logs' appId (query-params service=serviceName)}}Logs{{/link-to}}
            {{/link-to}}
          </ul>
        </ul>
      </div>
    </div>
    <div class="panel-body yarn-app-body">
      {{outlet}}
    </div>
  </div>
</div>

{{confirm-dialog
  dialogId="stopServiceConfirmDialog"
  message=(concat 'Are you sure you want to stop service "' model.serviceName '" for user "' model.app.user '" ?')
  action="stopService"
}}

{{confirm-dialog
  dialogId="deleteServiceConfirmDialog"
  message=(concat 'Are you sure you want to delete service "' model.serviceName '" for user "' model.app.user '" ?')
  action="deleteService"
}}

{{confirm-dialog
  dialogId="killApplicationConfirmDialog"
  message=(concat 'Are you sure you want to kill application "' model.app.id '"?')
  action="killApplication"
}}
