{% load bootstrap3 %}
{% load i18n %}
{% include 'editor/fragment_levels.html' %}

<h3>
    {% trans 'Graph' %}
    <small>
        {% if space %}
            {% with space.title as space_title %}
                {% blocktrans %}in space {{ space_title }}{% endblocktrans %}
            {% endwith %}
        {% else %}
            {% with level.title as level_title %}
                {% blocktrans %}on level {{ level_title }}{% endblocktrans %}
            {% endwith %}
        {% endif %}
    </small>
</h3>
<p>
    <a href="{{ back_url }}">&laquo; {{ back_title }}</a>
</p>
{% if parent_url %}
    <p>
        <a href="{{ parent_url }}">&laquo; {{ parent_title }}</a>
    </p>
{% endif %}
{% bootstrap_messages %}

{% if set_active_node %}
    <div data-active-node="{% if active_node %}{{ active_node.pk }}{% else %}null{% endif %}" class="well well-sm">
        <p>
            <strong>{% trans 'Active node:' %} {{ active_node.pk }}</strong><br>
            {% with space_title=active_node.space.title level_title=active_node.space.level.title %}
                {% blocktrans %}in space {{ space_title }}{% endblocktrans %}<br>
                {% blocktrans %}on level {{ level_title }}{% endblocktrans %}
            {% endwith %}
        </p>
        <form action="{{ request.path }}" method="post">
            {% csrf_token %}
            <input type="hidden" name="pk" value="{{ active_node.pk }}">
            <button type="submit" class="btn btn-danger btn-xs" name="delete" value="1">{% trans 'Delete Node' %}</button>
        </form><br>
        <strong>{% trans 'Connections:' %}</strong><br>
        {% for connections in active_node_connections %}
            <small>
                {% with space_title=connections.0.other_node.space.title level_title=connections.0.other_node.space.level.title %}
                    {% blocktrans %}Space {{ space_title }}{% endblocktrans %}<br>
                    {% blocktrans %}on level {{ level_title }}{% endblocktrans %}
                {% endwith %}
                <br>
                →
                {% for connection in connections %}
                    {% if connection.from_node_id == active_node.pk %}
                        {{ connection.other_node.pk }}{% if connection.waytype %} ({{ connection.waytype.title }}){% endif %}{% if connection.access_restriction_id %} ({{ connection.access_restriction.title }}){% endif %},
                    {% endif %}
                {% endfor %}
                <br>
                ←
                {% for connection in connections %}
                    {% if connection.from_node_id != active_node.pk %}
                        {{ connection.other_node.pk }}{% if connection.waytype %} ({{ connection.waytype.title }}){% endif %}{% if connection.access_restriction_id %} ({{ connection.access_restriction.title }}){% endif %},
                    {% endif %}
                {% endfor %}
            </small><br><br>
        {% endfor %}
    </div>
{% else %}
    <div data-active-node class="well well-sm"></div>
{% endif %}

<form action="{{ request.path }}" method="post" data-graph-editing{% if create_nodes %} data-graph-create-nodes{% endif %} data-nozoom>
    {% csrf_token %}

    <h4>{% trans 'Settings for new edges' %}</h4>
    {% bootstrap_form edge_settings_form %}

    {% bootstrap_form graph_action_form %}
</form>
