{% extends "admin/base_site.html" %}
{% load i18n %}

{% block coltype %}colSM{% endblock %}
{% block breadcrumbs %}
    <div class="flex items-center space-x-2">
        <a class="text-blue-500 hover:underline" href="{% url 'admin:index' %}">{% translate 'Home' %}</a>
        <span class="text-gray-500">&rsaquo;</span>
        <a class="text-blue-500 hover:underline"
           href="{% url 'django-admindocs-docroot' %}">{% translate 'Documentation' %}</a>
        <span class="text-gray-500">&rsaquo;</span>
        <span class="text-gray-500">{% translate 'Views' %}</span>
    </div>
{% endblock %}

{% block title %}{% translate 'Views' %}{% endblock %}

{% block content %}
    <h1 class="text-2xl font-semibold mb-4">{% translate 'View Documentation' %}</h1>

    {% regroup views|dictsort:'namespace' by namespace as views_by_ns %}

    <div id="content-related" class="sidebar">
        <div class="module">
            <h2 class="text-lg font-medium mb-2">{% translate 'Jump to Namespace' %}</h2>
            <ul class="list-disc pl-6 space-y-1">
                {% for ns_views in views_by_ns %}
                    <li>
                        <a class="text-blue-500 hover:underline" href="#ns|{{ ns_views.grouper }}">
                            {% if ns_views.grouper %}{{ ns_views.grouper }}
                            {% else %}{% translate "Empty namespace" %}{% endif %}
                        </a>
                    </li>
                {% endfor %}
            </ul>
        </div>
    </div>

    <div id="content-main" class="space-y-8">
        {% for ns_views in views_by_ns %}
            <div class="module">
                <h2 id="ns|{{ ns_views.grouper }}" class="text-xl font-semibold">
                    {% if ns_views.grouper %}
                        {% blocktranslate with ns_views.grouper as name %}Views by namespace
                            {{ name }}{% endblocktranslate %}
                    {% else %}
                        {% blocktranslate %}Views by empty namespace{% endblocktranslate %}
                    {% endif %}
                </h2>

                {% for view in ns_views.list|dictsort:"url" %}
                    {% ifchanged %}
                        <h3 class="text-lg text-blue-500"><a class="hover:underline"
                                                             href="{% url 'django-admindocs-views-detail' view=view.full_name %}">{{ view.url }}</a>
                        </h3>
                        <p class="text-gray-500">
                            {% blocktranslate with view.full_name as full_name and view.url_name as url_name %}
                                View function: <code>{{ full_name }}</code>. Name: <code>{{ url_name }}</code>.
                            {% endblocktranslate %}</p>
                        <p>{{ view.title }}</p>
                        <hr class="my-4">
                    {% endifchanged %}
                {% endfor %}
            </div>
        {% endfor %}
    </div>
{% endblock %}
