
<!--
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.
-->

<%
    var isLoaded = (model ? true : false);
    var isApp = (parentId ? false : true);

    // Only emphasise applications at the top level, not as indirect references.
    isApp &= !indirect;

    if (!isLoaded) {
%>
        <i>Loading... (<%- id %>)</i>
<%  } else {
        var hasChildren = model.hasChildren() || model.hasMembers();
        var iconUrl = model.get('iconUrl');

        var entityIconSize = isApp ? 40 : 30;
        var statusIconSize = isApp ? 24 : 16;

        var chevronLeft = (isApp ? 5.5 : 1.5);
        var minHeight = hasChildren && statusIconUrl ? entityIconSize : 24;
        var statusColumnWidth = hasChildren || statusIconUrl || (!isApp && !iconUrl /* for children, insert space so things line up */) ? statusIconSize : 0;
%>

  <span class="entity_tree_node name entity" id="span-<%- id %>" 
        data-entity-id="<%- id %>" data-entity-type="<%- model.get('type') %>" data-parent-id="<%- parentId %>" data-app-id="<%- model.get('applicationId') %>">
    <a href="#v1/applications/<%= encodeURIComponent(model.get('applicationId')) %>/entities/<%= encodeURIComponent(id) %>">

      <div style="min-width: <%- statusColumnWidth + (iconUrl ? entityIconSize : 6)%>px; min-height: <%= minHeight %>px; max-height: 40px; display: inline-block; margin-right: 4px; vertical-align: middle;">
        <% if (statusIconUrl) { %>
        <div style="position: absolute; left: 0px; margin: auto; top: <%= isApp && hasChildren ? 3 : 2 %>px;<% if (!hasChildren) { %> bottom: 0px;<% } %>">
            <img src="<%= encodeURI(statusIconUrl) %>" style="max-width: <%- statusIconSize %>px; max-height: <%- statusIconSize %>px; margin: auto; position: absolute; top: -1px;<% if (!hasChildren) { %> bottom: 0px;<% } %>">
        </div>
        <% } %>

        <% if (hasChildren) { %>
        <div style="position: absolute; left: <%- chevronLeft %>px; margin: auto; <%= encodeURI(statusIconUrl) ? "bottom: -1px;" : isApp ? "top: 6px;" : "top: 6px;" %>">
            <div class="toggler-icon icon-chevron-right tree-node-state tree-change">
                <div class="light-popup">
                    <div class="light-popup-body">
                        <div class="light-popup-menu-item tree-change tr-toggle tr-default">Toggle Children</div>
                        <div class="light-popup-menu-item tree-change tr-expand">Expand</div>
                        <div class="light-popup-menu-item tree-change tr-expand-all">Expand All</div>
                        <div class="light-popup-menu-item tree-change tr-collapse">Collapse</div>
                        <div class="light-popup-menu-item tree-change tr-collapse-all">Collapse All</div>
                    </div>
                </div>
            </div>
        </div>
        <% } %>

        <% if (iconUrl) { %>
            <img src="<%= encodeURI(iconUrl) %>" style="max-width: <%- entityIconSize %>px; max-height: <%- entityIconSize %>px; position: absolute; padding-left: 5px; left: <%- statusColumnWidth %>px; top: 0; bottom: 0; margin: auto;">
        <% } %>
      </div>

      <% if (indirect) { %>
        <i class="indirection-icon icon-share-alt"></i>
      <% } %>
      <span style="max-height: 18px; padding-right: 6px; position: relative; margin: auto; top: 2px; bottom: 0;"><%- model.get('name') %></span>

    </a>
  </span>

<% } %>