{% set breadcrumbs = breadcrumbs() %}
{% set protect = app.request.attributes.get('_route') ends with '_new' or app.request.attributes.get('_route') ends with '_edit' %}

<nav aria-label="breadcrumb" {{ attributes.defaults({class: 'w-max'}) }}>
  <ol class="flex w-full flex-wrap items-center rounded-md bg-slate-50 px-2 py-2 lg:px-4 dark:bg-slate-600">
    {# Maison (toujours un lien car jamais le dernier) #}
    <li class="hover:text-primary-hover flex cursor-pointer items-center text-sm text-slate-500 transition-colors duration-300 dark:text-slate-300">
      <a
        href="{{ path('admin_index') }}"
        class="text-primary hover:text-primary-hover"
        {% if protect %}
          data-turbo-method=""
          data-turbo-confirm="En annulant, vos modifications ne seront pas prises en compte. Souhaitez-vous continuer ?"
        {% endif %}>
        <svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" viewBox="0 0 20 20" fill="currentColor">
          <path d="M10.707 2.293a1 1 0 00-1.414 0l-7 7a1 1 0 001.414 1.414L4 10.414V17a1 1 0 001 1h2a1 1 0 001-1v-2a1 1 0 011-1h2a1 1 0 011 1v2a1 1 0 001 1h2a1 1 0 001-1v-6.586l.293.293a1 1 0 001.414-1.414l-7-7z"></path>
        </svg>
      </a>
      <span class="pointer-events-none mx-1 text-slate-500 lg:mx-2"> / </span>
    </li>

    {# Breadcrumbs dynamiques #}
    {% for breadcrumb_item in breadcrumbs %}
      <li class="{% if breadcrumb_item.uri and not loop.last %} {% endif %} flex cursor-pointer items-center text-sm text-slate-500 transition-colors duration-300 dark:text-slate-300">
        {% if breadcrumb_item.uri and not loop.last %}
          {# Liens = verts #}
          <a
            href="{{ breadcrumb_item.uri }}"
            class="text-primary hover:text-primary-hover"
            {% if protect %}
              data-turbo-method=""
              data-turbo-confirm="En annulant, vos modifications ne seront pas prises en compte. Souhaitez-vous continuer ?"
            {% endif %}>
            {{ breadcrumb_item.label }}
          </a>
        {% else %}
          {# Dernier élément = pas de lien, neutre #}
          <span>
            {{ breadcrumb_item.label }}
          </span>
        {% endif %}

        {% if not loop.last %}
          <span class="pointer-events-none mx-1 text-slate-500 lg:mx-2"> / </span>
        {% endif %}
      </li>
    {% endfor %}
  </ol>
</nav>
