<!-- array start -->
{% if search_query_attribute %}
  {% set base_search_query_attribute = search_query_attribute %}
{% else %}
  {% set base_search_query_attribute = "" %}
{% endif %}
<div class="row" style="padding-right: 0.75em;">
  <div class="col-md-3" style="text-align: right; margin-bottom: 5px;">
<strong>{{ schema.title }} <i class="fa fa-search" style="visibility:hidden" aria-hidden="true"></i></strong>
  </div>
{% if schema.style == "table" %}
</div>
<div style="padding-left:2.5em;">
  {% if schema["items"]["type"] == 'object' %}
  <table class="table">
    <thead>
      <tr>
        {% set item_property_names = schema["items"].properties.keys() %}
        {% set property_order = schema.get('items', {}).get('propertyOrder', []) %}
        {% for property_name in property_order %}
          {% if property_name in item_property_names %}
          {% set search_query_attribute = base_search_query_attribute + ".%s.%s" | format('?', property_name) %}
          <th scope="col">{{ schema["items"].properties[property_name].title }}
            {% if schema["items"].properties[property_name].type == 'text' %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == ""', advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% elif schema["items"].properties[property_name].type == 'quantity' %}
            {% if schema["items"].properties[property_name].units.strip() != '1' %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == 0' + schema["items"].properties[property_name].units, advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% else %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == 0', advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% endif %}
            {% elif schema["items"].properties[property_name].type == 'bool' %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == True', advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% else %}
            <a href="{{ url_for('.objects', q=search_query_attribute, advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% endif %}
          </th>
          {% endif %}
        {% endfor %}
        {% for property_name in item_property_names %}
          {% if property_name not in property_order %}
          {% set search_query_attribute = base_search_query_attribute + ".%s.%s" | format('?', property_name) %}
          <th scope="col">{{ schema["items"].properties[property_name].title }}
            {% if schema["items"].properties[property_name].type == 'text' %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == ""', advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% elif schema["items"].properties[property_name].type == 'quantity' %}
            {% if schema["items"].properties[property_name].units.strip() != '1' %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == 0' + schema["items"].properties[property_name].units, advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% else %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == 0', advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% endif %}
            {% elif schema["items"].properties[property_name].type == 'bool' %}
            <a href="{{ url_for('.objects', q=search_query_attribute + ' == True', advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% else %}
            <a href="{{ url_for('.objects', q=search_query_attribute, advanced='on') }}" class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% endif %}
          </th>
          {% endif %}
        {% endfor %}
      </tr>
    </thead>
    <tbody>
    {% if data is not none %}
      {% for item in data %}
        {% set name = "item" %}
        {% set schema = schema['items'] %}
        {% set data = item %}
        {% set entry_index = loop.index0 %}
        <tr>
        {% for property_name in property_order %}
          {% if property_name in item_property_names %}
          <td>
            {% set name = property_name %}
            {% set schema = schema.properties[property_name] %}
            {% if data is not none and property_name in data %}
            {% set data = data[property_name] %}
            {% else %}
            {% set data = none %}
            {% endif %}
            {% set search_query_attribute = base_search_query_attribute + ".%d.%s" | format(entry_index, name) %}
            {% include "objects/view/table_any.html" %}
          </td>
          {% endif %}
        {% endfor %}
        {% for property_name in item_property_names %}
          {% if property_name not in property_order %}
          <td>
            {% set name = property_name %}
            {% set schema = schema.properties[property_name] %}
            {% if data is not none and property_name in data %}
            {% set data = data[property_name] %}
            {% else %}
            {% set data = none %}
            {% endif %}
            {% set search_query_attribute = base_search_query_attribute + ".%d.%s" | format(entry_index, name) %}
            {% include "objects/view/table_any.html" %}
          </td>
          {% endif %}
        {% endfor %}
        </tr>
      {% endfor %}
    {% endif %}
    </tbody>
    <tfoot>
      <tr>
        {% for property_name in item_property_names %}
          <th scope="col"></th>
        {% endfor %}
      </tr>
    </tfoot>
  </table>
  {% elif schema["items"]["type"] == "array" %}
  {% set max_used_fields = [0] %}
  {% if data is not none %}
    {% for item in data %}
      {% if (item | length) > max_used_fields[-1] %}
        {% set tmp = max_used_fields.append(item | length) %}
      {% endif %}
    {% endfor %}
  {% endif %}
  {% set max_used_fields = max_used_fields [-1] %}
  <table class="table">
  <thead>
  <tr>
    {% for i in range(max_used_fields) %}
      <th>Field {{ (i+1) }}</th>
    {% endfor %}
  </tr>
  </thead>
  {% if data is not none %}
  {% for item in data %}
    {% set entry_index = loop.index0 %}
    <tr>
    {% for field in item %}
      <td>
          {% set name = "field_".format(loop.index0) %}
          {% set schema = schema["items"]["items"] %}
          {% set data = field %}
          {% set search_query_attribute = base_search_query_attribute + ".%d.%s" | format(entry_index, name) %}
          {% include "objects/view/table_any.html" %}
      </td>
    {% endfor %}
    </tr>
  {% endfor %}
  {% endif %}
  <tfoot>
  <tr>
    {% for i in range(max_used_fields) %}
      <th>Field {{ (i+1) }}</th>
    {% endfor %}
  </tr>
  </tfoot>
  </table>
  {% endif %}
</div>
{% elif schema.style == "list" %}
  <div class="col-md-9 array-style-list">
  {% if data %}
    <ul style="padding-left: 1.25em">
    {% for item in data %}
      {% set name = "item" %}
      {% set schema = schema['items'] %}
      {% set data = item %}
      {% set search_query_attribute = base_search_query_attribute + ".%d" | format(loop.index0) %}
      <li>{% include "objects/view/list_any.html" %}</li>
    {% endfor %}
    </ul>
  {% else %}
    &mdash;
  {% endif %}
  </div>
</div>
{% else %}
</div>
<div style="padding-left:2.5em;">
  {% if data is not none %}
    {% for item in data %}
      {% set name = "item" %}
      {% set schema = schema['items'] %}
      {% set data = item %}
      {% set search_query_attribute = base_search_query_attribute + ".%d" | format(loop.index0) %}
        <div style="border-left:1px solid #cccccc; border-bottom:1px solid #cccccc; border-top:1px solid #cccccc; border-right:1px solid #cccccc; margin-right:-1px; border-radius:5px 0 0 5px; padding-left:2.5em; padding-top:1em; margin-bottom: 1em;">
        {% include "objects/view/any.html" %}
        </div>
    {% endfor %}
  {% endif %}
</div>
{% endif %}
<!-- array end -->
