from __future__ import annotations

from django import template

register = template.Library()


@register.inclusion_tag("admin_frontend/_breadcrumbs.html", takes_context=True)
def render_breadcrumbs(context, breadcrumbs=None, aria_label: str = "Breadcrumb"):
    """
    Render breadcrumbs using a Tailwind-friendly partial.

    Usage in templates:
      {% load breadcrumbs %}
      {% render_breadcrumbs breadcrumbs %}

    "breadcrumbs" should be a list of (label, url) tuples.
    Set url to None for the current (active) crumb.
    """
    request = context.get("request")
    crumbs = breadcrumbs or context.get("breadcrumbs")
    if crumbs is None and request is not None:
        crumbs = getattr(request, "_breadcrumbs", [])
    return {"breadcrumbs": crumbs or [], "aria_label": aria_label, "request": request}
