<footer{{ attributes.addClass('fr-footer').setAttribute('role', 'contentinfo').setAttribute('id', 'footer') }}>
  {% if top %}
  <div class="fr-footer__top">
    <div class="fr-container">
      <div class="fr-grid-row fr-grid-row--start fr-grid-row--gutters">
          {% for category in top %}
          <div class="fr-col-12 fr-col-sm-3 fr-col-md-2">
              {% set category_attributes = create_attribute(category.attributes|default({})).addClass('fr-footer__top-cat') %}
              <h3{{ category_attributes }}>{{ category.title }}</h3>
              <ul class="fr-footer__top-list">
                {% for item in category.below %}
                  {% set item_attributes = create_attribute(item.attributes|default({})) %}
                  {% set link_attributes = create_attribute(item.link_attributes|default({})).addClass('fr-footer__top-link') %}
                  {% set link_attributes = item.url ? link_attributes.setAttribute('href', item.url) : link_attributes %}
                  {% if link_attributes.target == '_blank' %}
                    {% set link_attributes = link_attributes.setAttribute('title', '@title - new window'|t({'@title': link_attributes.title ?: item.title})) %}
                  {% endif %}
                <li{{ item_attributes }}><a{{ link_attributes }}>{{ item.title }}</a></li>
               {% endfor %}
              </ul>
          </div>
       {% endfor %}
      </div>
    </div>
  </div>
  {% endif %}
  <div class="fr-container">
    <div class="fr-footer__body">
      <div class="fr-footer__brand fr-enlarge-link">

        {% set logo_text = logo_text|default('République\nFrançaise') %}

        {% if not operator_logo %}
          <a href="{{ home_url|default('/') }}" title="{{ 'Homepage'|t }} - {{ service_title }} - {{ logo_text }}">
        {% endif %}
        <p class="fr-logo">
          {{ logo_text|nl2br }}
        </p>
        {% if not operator_logo %}
          </a>
        {% endif %}
        {% if operator_logo %}
          <a class="fr-footer__brand-link" href="{{ home_url|default('/') }}" title="{{ 'Homepage'|t }} - {{ operator_logo_alt|default(service_title) }} - {{ logo_text }}">
            {{ operator_logo }}
          </a>
        {% endif %}
      </div>
      {% if content or content_desc %}
        <div class="fr-footer__content">
          {% if content_desc %}
          <div class="fr-footer__content-desc">{{ content_desc }}</div>
          {% endif %}
        {{ _self.menu(content, 'content') }}
        </div>
      {% endif %}
    </div>
    {{ partners }}
    {% if bottom or bottom_copy %}
      <div class="fr-footer__bottom">
        {{ _self.menu(bottom, 'bottom') }}
        {% if bottom_copy %}
        <div class="fr-footer__bottom-copy">
          <div>{{ bottom_copy }}</div>
        </div>
        {% endif %}
      </div>
    {% endif %}
  </div>
</footer>

{% macro menu(items, variant = 'content') %}
<ul class="fr-footer__{{ variant }}-list">
  {% for item in items %}

    {% set item_attributes = item.attributes|default({}) %}
    {% set item_attributes = create_attribute(item_attributes) %}

    <li{{ item_attributes.addClass('fr-footer__' ~ variant ~ '-item') }}>
      {% set link_attributes = item.link_attributes|default({}) %}
      {% set link_attributes = create_attribute(link_attributes) %}
      {% set link_attributes = link_attributes.addClass('fr-footer__' ~ variant ~ '-link') %}

      {% if item.url %}
        {% set link_attributes = link_attributes.setAttribute('href', item.url) %}

        {% if link_attributes.target == '_blank' %}
          {% set link_attributes = link_attributes.setAttribute('title', '@title - new window'|t({'@title': link_attributes.title ?: item.title})) %}
        {% endif %}

        <a{{ link_attributes }}>
          {{ item.title }}
        </a>
     {% else %}
        <span{{ link_attributes }}>
          {{ item.title }}
        </span>
     {% endif %}
  </li>
  {% endfor %}
</ul>
{% endmacro %}
