{% extends "wagtailadmin/base.html" %}
{% load i18n %}
{% load static %}
{% load wagtailadmin_tags %}

{% block titletag %}{% trans "Block Inventory" %}{% endblock %}

{% block extra_css %}
<style>
    form.nice-padding {
        display: table;
        box-sizing: border-box;
        width: 100%;
    }
    .wagtail-inventory-select {
        display: table-row;
    }
    .wagtail-inventory-select .select {
        display: table-cell;
        padding: 0 10px 10px 0;
    }
    .wagtail-inventory-select .select-has {
        width: 175px;
    }
    .wagtail-inventory-select .field-content {
        width: 100%;
    }
</style>
{% endblock %}

{% block extra_js %}
   {{ block.super }}
   <script>
       window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'PAGE';
   </script>
   <script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
{% endblock %}

{% block content %}
{% trans "Block Inventory" as header_str %}
{% include "wagtailadmin/shared/header.html" with title=header_str icon="placeholder" %}

<form class="nice-padding" action="{% url 'wagtailinventory:search' %}">
	{{ formset.management_form }}
  {% for form in formset %}
    <div class="wagtail-inventory-select">
      {% include "wagtailadmin/shared/field.html" with field=form.has show_label=False field_classes="select-has" %}
      {% include "wagtailadmin/shared/field.html" with field=form.block show_label=False field_classes="select-block" %}
    </div>
  {% endfor %}
  <input type="submit" value="Find matching pages" class="button" style="margin: 10px 0 20px;" />
</form>

<div id="search-results">
  {% if pages %}
    <div class="nice-padding">
      <h2>
        {% blocktrans count counter=pages.paginator.count %}
            There is one match
        {% plural %}
            There are {{ counter }} matches
        {% endblocktrans %}
      </h2>

      {% include "wagtailinventory/_list_explore_inventory.html" with show_parent=1 show_bulk_actions=1 %}
      {% include "wagtailadmin/shared/pagination_nav.html" with items=pages %}
      {% trans "Select all pages in listing" as select_all_text %}
      {% include 'wagtailadmin/bulk_actions/footer.html' with select_all_obj_text=select_all_text app_label='wagtailcore' model_name='page' objects=pages %}
    </div>
  {% else %}
    <div class="nice-padding">
      <h2>
        {% blocktrans %}Sorry, there are no matching pages.{% endblocktrans %}
      </h2>
    </div>
  {% endif %}
</div>
{% endblock %}
