{% extends "base.html" %}

{% load static dsfr_tags wagtailcore_tags wagtailimages_tags i18n %}

{% block title %}
  {% if page %}
    <title>{{ page.seo_title|default:page.title }}
      {% if extra_title %}: {{ extra_title }}{% endif %}
    — {{ settings.sites_conformes_content_manager.CmsDsfrConfig.site_title }}</title>
  {% else %}
    <title>{{ title }} — {{ settings.sites_conformes_content_manager.CmsDsfrConfig.site_title }}</title>
  {% endif %}
{% endblock title %}

{% block description %}
  <meta name="description" content="{{ search_description }}" />
{% endblock description %}

{% block social_media %}
  <meta property="og:site_name"
        content="{{ settings.sites_conformes_content_manager.CmsDsfrConfig.site_title }}" />
  <meta property="og:title" content="{{ title }}" />
  <meta property="og:type" content="website" />
  <meta property="og:url" content="{{ request.build_absolute_uri }}" />
  <meta property="og:description" content="{{ search_description }}" />
  <meta property="og:locale" content="{{ LANGUAGE_CODE }}" />

  <meta name="twitter:title" content="{{ title }}" />
  <meta name="twitter:description" content="{{ search_description }}" />
{% endblock social_media %}

{% block content %}
  <div class="fr-container fr-my-6w">
    {% if page %}
      {% include "sites_conformes_content_manager/blocks/breadcrumbs.html" %}
    {% else %}
      {% dsfr_breadcrumb breadcrumb %}
    {% endif %}
    {% if page %}
      <h1>
        {{ page.title }}
        {% if extra_title %}: {{ extra_title }}{% endif %}
        {% include "sites_conformes_content_manager/blocks/page_visibility.html" %}
      </h1>

    {% else %}
      <h1>{% translate "Tags" %}</h1>
    {% endif %}

    {% include "sites_conformes_content_manager/blocks/messages.html" %}

    <div class="fr-mb-2w">
      {% for first_letter in sorted_tags.keys|dictsort:0 %}
        <a href="#{{ first_letter }}" class="fr-tag">{{ first_letter }}</a>
      {% endfor %}
    </div>

    {% for first_letter, tags in sorted_tags.items|dictsort:0 %}
      <h2 id="{{ first_letter }}">{{ first_letter }}</h2>
      <ul>
        {% for tag in tags|dictsort:"slug" %}
          <li>
            {% if page %}
              <a href="{% pageurl page %}?tag={{ tag.slug }}"><strong>{{ tag.name }}</strong> ({{ tag.usecount }})</a>
            {% else %}
              <a href="{% url 'global_tag' tag.slug %}"><strong>{{ tag.name }}</strong> ({{ tag.usecount }})</a>
            {% endif %}
          </li>
        {% endfor %}
      </ul>
    {% endfor %}
  </div>
{% endblock content %}
