{% extends "base.html" %}
{% load mptt_tags %}

{% block title %}{{ referenz.Path }} - Referenzen{% endblock %}

{% block content %}
<div class="container-fluid">
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item"><a href="/">Startseite</a></li>
      <li class="breadcrumb-item"><a href="/referenzen">Referenzen</a></li>
      {% if referenz.ParentID %}
      <li class="breadcrumb-item"><a href="../{{ referenz.ParentID }}">Übergeordnet</a></li>
      {% endif %}
      <li class="breadcrumb-item active" aria-current="page">{{ referenz.name_nummer }}</li>
    </ol>
  </nav>

  <h1>{{ referenz.Path }}</h1>

  {% if referenz.url %}
  <p>
    <a href="{{ referenz.url }}" class="btn btn-secondary icon icon--before icon--external" target="_blank" rel="noopener">
      Externe Referenz öffnen
    </a>
  </p>
  {% endif %}

  {% if referenz.erklaerung %}
  <div class="row">
    <div class="col-md-12">
      <div class="card mb-4">
        <div class="card-header">
          <h2 class="h4 mb-0">Beschreibung</h2>
        </div>
        <div class="card-body">
          {% for typ, html in referenz.erklaerung %}
          {% if html %}
          <div class="mb-2">{{ html|safe }}</div>
          {% endif %}
          {% endfor %}
        </div>
      </div>
    </div>
  </div>
  {% endif %}

  <div class="row">
    <div class="col-md-12">
      <div class="card mb-4">
        <div class="card-header">
          <h2 class="h4 mb-0">Referenzierte Vorgaben</h2>
        </div>
        <div class="card-body">
          <div class="referenz-tree">
            {% recursetree referenz.children %}
            <div class="mb-3">
              <strong>
                {% if not node == referenz %}
                <a href="../{{ node.id }}">{{ node.Path }}</a>
                {% else %}
                {{ node.Path }}
                {% endif %}
              </strong>

              {% if node.referenziertvon %}
              <ul class="list-unstyled mt-2 ml-3">
                {% for ref in node.referenziertvon %}
                <li class="mb-1">
                  <a href="{% url 'standard_detail' nummer=ref.dokument.nummer %}#{{ ref.Vorgabennummer }}"
                     class="icon icon--before icon--external">
                    {{ ref }}
                  </a>
                </li>
                {% endfor %}
              </ul>
              {% endif %}

              {% if not node.is_leaf_node %}
              <div class="ml-4 mt-2">
                {{ children }}
              </div>
              {% endif %}
            </div>
            {% endrecursetree %}
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}