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

{% block subtitle %}{{ _(dataset_type.title()) }}{% endblock %}

{% block breadcrumb_content %}
  <li class="active">{{ h.nav_link(_(dataset_type.title() + 's'), named_route='%s.search' % dataset_type) }}</li>
{% endblock %}

{% block primary_content %}
  <section class="module">
    <div class="module-content">
      {% block page_primary_action %}
        {% if h.check_access('package_create') %}
          <div class="page_primary_action">
            {% snippet 'snippets/add_dataset.html', dataset_type=dataset_type %}
          </div>
        {% endif %}
      {% endblock %}
      {% block form %}
        {% set facets = {
          'fields': fields_grouped,
          'search': search_facets,
          'titles': facet_titles,
          'translated_fields': translated_fields,
          'remove_field': remove_field }
        %}
        {% set sorting = [
          (_('Relevance'), 'score desc, metadata_modified desc'),
          (_('Name Ascending'), 'title_string asc'),
          (_('Name Descending'), 'title_string desc'),
          (_('Last Modified'), 'metadata_modified desc')
          ]
        %}
        {% snippet 'snippets/search_form.html', form_id='dataset-search-form', type=dataset_type, query=q, sorting=sorting, sorting_selected=sort_by_selected, count=page.item_count, placeholder=h.humanize_entity_type('package', dataset_type, 'search placeholder') or _('Search datasets...'), facets=facets, show_empty=request.args, error=query_error, fields=fields %}
      {% endblock %}
      {% block package_search_results_list %}
        {% snippet 'snippets/package_list.html', packages=page.items %}
      {% endblock %}
    </div>

    {% block page_pagination %}
      {{ page.pager(q=q) }}
    {% endblock %}
  </section>

  {% block package_search_results_api %}
    <section class="module">
      <div class="module-content">
        {% block package_search_results_api_inner %}
          <small>
            {% set api_link = h.link_to(_('API'), h.url_for('api.get_api', ver=3)) %}
            {% set api_doc_link = h.link_to(_('API Docs'), 'https://docs.ckan.org/en/{0}/api/'.format(g.ckan_doc_version)) %}
            {% trans %} You can also access this registry using the {{ api_link }} (see {{ api_doc_link}}). {% endtrans %}
          </small>
        {% endblock %}
      </div>
    </section>
  {% endblock %}
{% endblock %}


{% block secondary_content %}
  <div class="filters">
    <div>
      {% for facet in facet_titles %}
        {% snippet 'snippets/facet_list.html', title=facet_titles[facet], name=facet, search_facets=search_facets %}
      {% endfor %}
    </div>
    <a class="close no-text hide-filters"><i class="fa fa-times-circle"></i><span class="text">close</span></a>
  </div>
{% endblock %}
