{% extends "base.html" %}

{% macro entity_tab(name, text, url_suffix, count=None) %}
<a href ="{% if editgroup %}/editgroup/{{ editgroup.editgroup_id }}{% endif %}/{{ entity_type }}/{% if entity.ident %}{{ entity.ident }}{% elif entity.revision %}rev/{{ entity.revision }}{% endif %}{{ url_suffix }}" class="{% if entity_view == name %}active{% endif %} item" style="padding: 0em 1.2em;">{{ text }}{% if count != None %} ({{ count }}){% endif %}</a>
{% endmacro %}

{% block fullmain %}
<main {% block main_extra_attr %}{% endblock %}>
<div class="ui vertical stripe segment" style="background-color: #EEE; padding-top: 5em; padding-bottom: 0px; border-bottom: 0px;">
  <div class="ui container">
    <div class="ui centered grid">
      <div class="fifteen wide large screen sixteen wide column" style="padding-bottom: 0px;">
        <h1 class="ui header">
          {% if entity_type == "container" %}
            {{ entity.name }}
          {% elif entity_type == "creator" %}
            {{ entity.display_name }}
          {% elif entity_type == "file" %}
          {% elif entity_type == "fileset" %}
          {% elif entity_type == "webcapture" %}
            {% if entity.original_url %}
              <a href="{{ entity.original_url }}" style="color: black;"><code>{{ entity.original_url }}</code></a>
            {% endif %}
          {% elif entity_type == "release" %}
            <span itemprop="headline"><span itemprop="name">{{ entity.title }}</span></span>
            {% if entity.subtitle %}
              <br><span style="font-size: smaller; font-weight: normal;">{{ entity.subtitle }}</span>
            {% endif %}
          {% endif %}
          <span class="sub header">
            <code>
              {% if entity.ident %}
                {{ entity_type }}_{{ entity.ident }}
              {% elif entity.revision %}
                {{ entity_type }}_rev_{{ entity.revision }}
              {% endif %}
              {% if editgroup %}
                <a href="/editgroup/{{ editgroup.editgroup_id }}" style="color: purple;">
                  [as of editgroup_{{ editgroup.editgroup_id }}]
                </a>
              {% endif %}
            </code>
          </span>
        </h1>
        {% if entity_type == "release" %}
          <p style="font-size: larger;">
          {% if entity._authors and entity._authors != [] %} by
            {% for contrib in entity._authors[:12] %}
              {% if contrib.creator_id %}
                <b><a href="/creator/{{contrib.creator_id}}">{{ contrib.raw_name }}</a></b>{% if not loop.last %}, {% endif %}
              {% else %}
                {% if contrib.raw_name != None %}{{ contrib.raw_name }}{% else %}<i>Unknown</i>{% endif %}{% if not loop.last %}, {% endif %}
              {% endif %}
            {% endfor %}
            {% if entity._authors|count > 12 %} <b>(+{{ entity._authors|length - 12 }} others)</b>
            {% endif %}
            <br>
          {% endif %}
        {% endif %}
        <div class="ui container" style="min-width: 40em;">
          <div class="ui small tabular compact menu">
            {{ entity_tab("overview", "Overview", "") }}
            {% if entity_type == "release" %}
              {{ entity_tab("contribs", "Authors", "/contribs", entity._authors|count ) }}
              {{ entity_tab("references", "References", "/references", entity.refs|count) }}
            {% endif %}
            {{ entity_tab("metadata", "Metadata", "/metadata") }}
          </div>
          {% if entity.ident %}
            <div class="ui small tabular compact menu floated right">
              {% if (entity.state != 'wip' and not editgroup) or (editgroup and not (editgroup.changelog_index or editgroup.submitted )) %}
                {{ entity_tab("edit", "Edit", "/edit") }}
              {% endif %}
              {% if not editgroup %}
                {{ entity_tab("history", "History", "/history") }}
              {% endif %}
            </div>
          {% endif %}
        </div>
      </div>
    </div>
  </div>
</div>

<div class="ui container" style="padding-top: 3em;">
  <div class="ui centered grid">
    <div class="fifteen wide large screen sixteen wide column" style="padding-bottom: 0px;">
    {% block entity_main %}{% endblock %}
    </div>
  </div>
</div>
</main>
{% endblock %}

{% block postscript %}
<script>
  $('.ui.accordion').accordion();
</script>
{% endblock %}