{% extends "mapentity/base_site.html" %}
{% load i18n static mapentity_tags leaflet_tags %}

{% block title %}{{ object }} | {{ block.super }}{% endblock title %}

{% block mainpanel %}
<div class="details-panel detail col-12 col-lg-7 {{ modelname }}">
  <h1 class="details-title">{{ object }}</h1>
  <div class="download-group">
    <div class="btn-group">
      {% block download %}
      {% if mapentity_weasyprint %}
      <a class="btn btn-light btn-sm" rel="noopener noreferrer" target="_blank" href="{{ object.get_document_url }}"><img src="{% static "paperclip/fileicons/pdf.png" %}"/> {% trans "PDF" %}</a>
      {% else %}
      <a class="btn btn-light btn-sm" rel="noopener noreferrer" target="_blank" href="{{ object.get_document_url }}"><img src="{% static "paperclip/fileicons/odt.png" %}"/> {% trans "ODT" %}</a>
      <a class="btn btn-light btn-sm" rel="noopener noreferrer" target="_blank" href="{% url 'mapentity:convert' %}?url={{ object.get_document_url|urlencode }}&to=doc"><img src="{% static 'paperclip/fileicons/doc.png' %}"/> {% trans "DOC" %}</a>
      <a class="btn btn-light btn-sm" rel="noopener noreferrer" target="_blank" href="{% url 'mapentity:convert' %}?url={{ object.get_document_url|urlencode }}"><img src="{% static 'paperclip/fileicons/pdf.png' %}"/> {% trans "PDF" %}</a>
      {% endif %}
      {% endblock download %}
    </div>
  </div>

  <div class="tabbable">
    <ul class="nav nav-tabs">
        <li class="nav-item">
          <a id="tab-properties" class="nav-link active" href="#properties" data-toggle="tab"><i class="bi bi-list-task"></i>
            <span class="d-none d-sm-inline">{% trans "Properties" %}</span>
            {% smart_include "propertiestab" %}
          </a>
        </li>
        {% block before_attachments_extra_tab_nav %}
        {% endblock %}
        <li class="nav-item">
          <a id="tab-attachments" class="nav-link" href="#attachments" data-toggle="tab"><i class="bi bi-file-earmark"></i>
            <span class="d-none d-sm-inline">{% trans "Attached files" %} ({{ object.attachments.count }})</span></a>
        </li>
        {% block after_attachments_extra_tab_nav %}
        {% endblock %}
      {% if ACTION_HISTORY_ENABLED %}
      <li class="nav-item">
        <a id="tab-history" class="nav-link" href="#history" data-toggle="tab"><i class="bi bi-clock-history"></i>
          <span class="d-none d-sm-inline">{% trans "History" %}</span></a>
      </li>
      {% endif %}
      {% if can_edit %}
      <a class="btn btn-primary ml-auto" href="{{ object.get_update_url }}"><i class="bi bi-pencil-square"></i> {% trans "Update" %}</a>
      {% else %}
      <span class="btn disabled ml-auto" href="#"><i class="bi bi-pencil-square"></i> {% trans "Update" %}</span>
      {% endif %}
    </ul>
    <div class="tab-content scrollable">

        <div id="properties" class="tab-pane active show">
          {% block detailspanel %}
          {% include template_attributes %}
          {% endblock detailspanel %}
        </div>
        {% block before_attachments_extra_tab_content %}
        {% endblock %}
        <div id="attachments" class="tab-pane">
          {% block attachmentspanel %}
          {% include 'paperclip/attachment_list.html' with attachment_form_next=object.get_detail_url|add:'?tab=attachments' %}
          {% endblock attachmentspanel %}
        </div>
        {% block after_attachments_extra_tab_content %}
        {% endblock %}
      {% if ACTION_HISTORY_ENABLED %}
      <div id="history" class="tab-pane">
        <table id="logentries-list" class="table table-striped table-bordered">
          <thead>
          <tr>
            <th>{% trans "Date" %}</th>
            <th>{% trans "User" %}</th>
            <th>{% trans "Action" %}</th>
          </tr>
          </thead>
          <tbody>
          {% for logentry in logentries %}
          <tr>
            <td>{{ logentry.action_time }} ({{ logentry.action_time|timesince }})</td>
            <td>{{ logentry.user }}</td>
            <td>{{ logentry.action_flag_display }}{% if logentry.change_message %} - {{ logentry.change_message }}{% endif %}</td>
          </tr>
          {% empty %}
          <tr>
            <td colspan="3">{% trans "None" %}</td>
          </tr>
          {% endfor %}
          {% if logentries_hellip %}
          <tr>
            <td>&hellip;</td>
            <td>&hellip;</td>
            <td>&hellip;</td>
          </tr>
          {% endif %}
          </tbody>
        </table>
        <a href="{% url 'mapentity:logentry_list' %}?content_type={{ object.get_content_type_id }}&object_id={{ object.pk }}" class="btn btn-light">{% trans "Full history" %}</a>
      </div>
      {% endif %}
    </div>
  </div>
</div><!-- col-md-7 -->

<div class="map-panel detail col-12 col-lg-5" {% if mapwidth and mapheight %}style="width: {{ mapwidth }}px; height: {{ mapheight }}px;"{% endif %}>
  {% block mappanel %}
  {% if object.get_geom %}
  {% include "mapentity/mapgeometry_fragment.html" with mapname="detailmap" %}
  {% else %}
  <p class="nomap">{{ empty_map_message }}</p>
  {% endif %}
  {% endblock mappanel %}
</div><!-- col-md-5 -->

{% endblock mainpanel %}
{% block extrabody %}
  {{ block.super}}
  <script type="text/javascript" src="{% static 'mapentity/mapentity.detail.js' %}"></script>
{% endblock %}
