{% load i18n admin_extras favorites %}

{% if app_list %}
  {% favorite_map as favorites_map %}
  {% favorite_entries app_list favorites_map as favorite_entries %}
  {% if favorite_entries %}
    <div class="module favorites-module">
      <table>
        <caption class="visually-hidden">{% translate 'Favorite models' %}</caption>
        <thead class="visually-hidden">
          <tr>
            <th scope="col">{% translate 'Model name' %}</th>
            <th scope="col">{% translate 'Model actions' %}</th>
            <th scope="col">{% translate 'Add link' %}</th>
            <th scope="col">{% translate 'Change or view list link' %}</th>
          </tr>
        </thead>
        <tbody>
        {% for entry in favorite_entries %}
          {% with app=entry.app model=entry.model fav=entry.favorite ct_id=entry.ct_id %}
            {% model_app_label model app.app_label as model_app_label %}
            {% with model_name=model.object_name|lower %}
            {% include "admin/includes/dashboard_model_row.html" with app_label=app.app_label model=model fav=fav ct_id=ct_id model_app_label=model_app_label model_name=model_name row_dom_id="favorites-"|add:model_app_label|add:"-"|add:model_name %}
            {% endwith %}
          {% endwith %}
        {% endfor %}
        </tbody>
      </table>
    </div>
  {% endif %}
  {% celery_feature_enabled as celery_enabled %}
  {% for app in app_list %}
    {% if app.app_label != 'django_celery_beat' or celery_enabled %}
    <div class="app-{{ app.app_label }} module{% if app.app_url in request.path|urlencode %} current-app{% endif %}" data-app-label="{{ app.app_label }}">
      <table>
        <caption class="app-caption">
          <div class="app-caption-inner">
            <a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a>
          </div>
        </caption>
        <thead class="visually-hidden">
          <tr>
            <th scope="col">{% translate 'Model name' %}</th>
            <th scope="col">{% translate 'Model actions' %}</th>
            <th scope="col">{% translate 'Add link' %}</th>
            <th scope="col">{% translate 'Change or view list link' %}</th>
          </tr>
        </thead>
        <tbody id="app-{{ app.app_label }}-models">
        {% for model in app.models %}
          {% model_app_label model app.app_label as model_app_label %}
          {% with model_name=model.object_name|lower %}
            {% favorite_ct_id model_app_label model.object_name as ct_id %}
            {% favorite_from_map favorites_map ct_id as fav %}
            {% if not fav %}
            {% include "admin/includes/dashboard_model_row.html" with app_label=app.app_label model=model fav=fav ct_id=ct_id model_app_label=model_app_label model_name=model_name row_dom_id=model_app_label|add:"-"|add:model_name %}
            {% endif %}
          {% endwith %}
        {% endfor %}
        </tbody>
      </table>
    </div>
    {% endif %}
  {% endfor %}
{% else %}
  <p>{% translate 'You don’t have permission to view or edit anything.' %}</p>
{% endif %}
