{% extends 'base/layout.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load perms %}
{% load plugins %}
{% load plugin_helpers %}
{% load plugin_buttons %}

{% block header %}
  {# Breadcrumbs #}
  <nav class="breadcrumb-container px-3" aria-label="breadcrumb">
    <ol class="breadcrumb">
      {% block breadcrumbs %}
        <li class="breadcrumb-item"><a href="{% url object|plugin_viewname:'list' %}">{{ object|meta:'verbose_name_plural'|bettertitle }}</a></li>
      {% endblock %}
    </ol>
  </nav>
  {{ block.super }}
{% endblock %}

{% block title %}{{ object }}{% endblock %}

{% block subtitle %}
  <div class="object-subtitle">
    <span>Created {{ object.created|annotated_date }}</span>
    <span class="separator">&middot;</span>
    <span>Updated <span title="{{ object.last_updated }}">{{ object.last_updated|timesince }}</span> ago</span>
  </div>
{% endblock %}

{% block controls %}
  {# Clone/Edit/Delete Buttons #}
  <div class="controls">
    <div class="control-group">
      {% plugin_buttons object %}

      {# Extra buttons #}
      {% block extra_controls %}{% endblock %}

      {% if object.clone_fields and request.user|can_add:object %}
        {% plugin_clone_button object %}
      {% endif %}
      {% if request.user|can_change:object %}
        {% plugin_edit_button object %}
      {% endif %}
      {% if request.user|can_delete:object %}
        {% plugin_delete_button object %}
      {% endif %}

    </div>
    <div class="control-group">
      {% custom_links object %}
    </div>
  </div>
{% endblock controls %}

{% block tabs %}
  <ul class="nav nav-tabs px-3">
    {% block tab_items %}
      <li class="nav-item" role="presentation">
        <a class="nav-link{% if not active_tab %} active{% endif %}" href="{{ object.get_absolute_url }}">{{ object|meta:"verbose_name"|bettertitle }}</a>
      </li>
    {% endblock tab_items %}
    {% if perms.extras.view_journalentry %}
      {% with journal_viewname=object|plugin_viewname:'journal' %}
        {% url journal_viewname pk=object.pk as journal_url %}
        {% if journal_url %}
          <li role="presentation" class="nav-item">
            <a href="{{ journal_url }}" class="nav-link{% if active_tab == 'journal'%} active{% endif %}">
              Journal {% badge object.journal_entries.count %}
            </a>
          </li>
        {% endif %}
      {% endwith %}
    {% endif %}
    {% if perms.extras.view_objectchange %}
      {% with changelog_viewname=object|plugin_viewname:'changelog' %}
        {% url changelog_viewname pk=object.pk as changelog_url %}
        {% if changelog_url %}
          <li role="presentation" class="nav-item">
              <a href="{{ changelog_url }}" class="nav-link{% if active_tab == 'changelog'%} active{% endif %}">Change Log</a>
          </li>
        {% endif %}
      {% endwith %}
    {% endif %}
  </ul>
{% endblock tabs %}

{% block content-wrapper %}
  <div class="tab-content">
    {% block content %}{% endblock %}
  </div>
{% endblock %}
