{#
Displays a sidebar module with navigation containing the provided resources.
If no resources are provided then the module will not be displayed.

pkg       - The package dict that owns the resources.
active    - The id of the currently displayed resource.
action    - The resource action to use (default: 'read', meaning route 'resource.read').

Example:

  {% snippet "package/snippets/resources.html", pkg=pkg, active=res.id %}

#}
{% set resources = pkg.resources or [] %}
{% set can_edit = pkg and h.check_access('package_update', {'id':pkg.id }) %}
{% if pkg and resources %}
  {% block resources %}
    <section class="module module-narrow resources">
      {% block resources_inner %}
        {% block resources_title %}
          <h2 class="module-heading"><i class="fa fa-bars"></i> {{ _("Resources") }}</h2>
        {% endblock %}
        {% block resources_list %}
          <ul class="list-unstyled nav nav-simple">
            {% for resource in resources %}
              {% set url = h.url_for('%s_resource.read' % pkg.type, id=pkg.name, resource_id=resource.id) %}
              {% if active == resource.id %}
                <li class="nav-item active">
                  <a href="#" title="{{ h.resource_display_name(resource) }}">{{ h.resource_display_name(resource)|truncate(25) }}</a>
                </li>
              {% elif can_edit %}
                <li class="nav-item d-flex justify-content-between position-relative">
                  <a class="flex-fill" href="{{ url }}" title="{{ h.resource_display_name(resource) }}">{{ h.resource_display_name(resource)|truncate(25) }}</a>
                  <div class="dropdown position-absolute end-0 me-2">
                    <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="dropdownRes{{ loop.index }}" data-bs-toggle="dropdown" aria-expanded="false"><i class="fa fa-wrench"></i></button>
                    <ul class="dropdown-menu" aria-labelledby="dropdownRes{{ loop.index }}">
                      <li>{% link_for _('Edit resource'), named_route=pkg.type ~ '_resource.edit', id=pkg.name, resource_id=resource.id, class_='dropdown-item', icon='pencil' %}</li>
                      {% block resources_list_edit_dropdown_inner scoped %}{% endblock %}
                      <li>{% link_for _('Views'), named_route=pkg.type ~ '_resource.views', id=pkg.name, resource_id=resource.id, class_='dropdown-item', icon='chart-bar' %}</li>
                    </ul>
                  </div>
                </li>
              {% else %}
                <li class="nav-item">
                  <a href="{{ url }}" title="{{ h.resource_display_name(resource) }}">{{ h.resource_display_name(resource)|truncate(25) }}</a>
                </li>
              {% endif %}
            {% endfor %}
          </ul>
        {% endblock %}
      {% endblock %}
    </section>
  {% endblock %}
{% endif %}

{% if can_edit and not is_activity_archive %}
  <div class="module-content">
    {% link_for _('Add new resource'), named_route=pkg.type ~ '_resource.new', id=pkg.name, class_='btn btn-default btn-sm', icon='plus' %}
  </div>
{% endif %}
