{% import 'macros/form.html' as form %}
{% extends "package/resource_edit_base.html" %}

{% block subtitle %}{{ _('View') }} {{ g.template_title_delimiter }} {{ h.resource_display_name(res) }}{% endblock %}

{% block page_primary_action %}
  {% if h.check_access('resource_view_create', {'resource_id': resource.id}) %}
    <div class="dropdown btn-group">
      <a class="btn btn-primary dropdown-toggle" role="button" id="dropdownView" data-bs-toggle="dropdown" aria-expanded="false" href="#">
        <i class="fa fa-plus-square"></i>
        {{ _('New view') }}
        <span class="caret"></span>
      </a>
      <ul class="dropdown-menu" aria-labelledby="dropdownView">
        {% for option in h.get_allowed_view_types(resource, pkg_dict)  %}
          {% set url = h.url_for(pkg_dict.type ~ '_resource.edit_view', id=pkg_dict.name, resource_id=resource.id, view_type=option[0]) %}
          <li><a href="{{ url }}" class="dropdown-item"><i class="fa fa-{{ option[2] }}"></i> {{ option[1] }}</a></li>
        {% endfor %}
      </ul>
    </div>
  {% endif %}
  {% asset 'vendor/reorder' %}
{% endblock %}

{% block primary_content_inner %}
  <h1>{{ _('Edit Views') }}</h1>
  {% if views %}
    {% snippet "package/snippets/resource_views_list.html", views=views, pkg=pkg, is_edit=true, extra_attributes='data-module = resource-view-reorder data-module-id=' + resource.id, extra_class='flex-column resource-view-list nav-pills nav-stacked' %}
  {% else %}
    <p class="empty">{{ _('This resource has no views') }}</p>
  {% endif %}
{% endblock %}
