{% extends "wagtailadmin/shared/breadcrumbs.html" %}
{% load i18n wagtailadmin_tags %}

{% comment "text/markdown" %}
    The breadcrumb component is reused across all of Wagtail’s headers when the page tree context is needed.
    Variables this template accepts:

    `items` - A list of wagtail page objects
    `trailing_breadcrumb_title` (string?) - use this for a non linkable last breadcrumb
    `classname` - Modifier classes
    `is_expanded` - Whether the breadcrumbs are always expanded or not, if True the breadcrumbs will not be collapsible
{% endcomment %}

{% block breadcrumbs_items %}
    {% for page in items %}
        {% if page.is_root and url_root_name %}
            {% url url_root_name as breadcrumb_url %}
        {% else %}
            {% url url_name page.id as breadcrumb_url %}
        {% endif %}
        {% if page.is_root %}
            <li
                class="{{ breadcrumb_item_classes }} {% if forloop.last %}w-font-bold{% endif %} {% if not is_expanded %}w-max-w-0{% endif %}"
                {% if not is_expanded %}hidden{% endif %}
                data-w-breadcrumbs-target="content"
            >
                <a
                    class="{{ breadcrumb_link_classes }}"
                    href="{{ breadcrumb_url }}{{ querystring_value }}"
                >
                    {% trans "Root" %}
                </a>
                {% icon name="arrow-right" classname=icon_classes %}
            </li>
        {% elif forloop.first %}
            {# For limited-permission users whose breadcrumb starts further down from the root #}
            <li
                class="{{ breadcrumb_item_classes }} {% if not is_expanded %}w-max-w-0{% endif %}"
                {% if not is_expanded %}hidden{% endif %}
                data-w-breadcrumbs-target="content"
            >
                <a class="{{ breadcrumb_link_classes }}" href="{{ breadcrumb_url }}{{ querystring_value }}">
                    {% trans "Root" %}
                </a>
                {% icon name="arrow-right" classname=icon_classes %}
            </li>
        {% elif forloop.last %}
            <li
                class="{{ breadcrumb_item_classes }} w-font-bold"
                {% if trailing_breadcrumb_title and not is_expanded %}hidden{% endif %}
                {% if trailing_breadcrumb_title or is_expanded %}data-w-breadcrumbs-target="content"{% endif %}
            >
                <a class="{{ breadcrumb_link_classes }}"
                    href="{{ breadcrumb_url }}{{ querystring_value }}">
                    {{ page.get_admin_display_title }}
                </a>
                {% if trailing_breadcrumb_title %}
                    {% icon name="arrow-right" classname=icon_classes %}
                {% endif %}
            </li>
        {% else %}
            <li
                class="{{ breadcrumb_item_classes }} {% if not is_expanded %}w-max-w-0{% endif %}"
                {% if not is_expanded %}hidden{% endif %}
                data-w-breadcrumbs-target="content"
            >
                <a class="{{ breadcrumb_link_classes }}" href="{{ breadcrumb_url }}{{ querystring_value }}">
                    {{ page.get_admin_display_title }}
                </a>
                {% icon name="arrow-right" classname=icon_classes %}
            </li>
        {% endif %}
    {% endfor %}
    {% if trailing_breadcrumb_title %}
        <li class="{{ breadcrumb_item_classes }}">
            <div class="w-flex w-justify-start w-items-center">
                {{ trailing_breadcrumb_title }}
            </div>
        </li>
    {% endif %}
{% endblock %}
