{% set container_style = schema.get('style') %}
<div class="row" style="padding-right: 0.75em;">
  {% include "objects/property_label.html" %}
</div>
<div {% if get_style_variant(schema.style, template_mode) == "full_width_table" %}class="full-width-table-wrapper"{% else %}style="padding-left:2.5em;"{% endif %}>
  {% if schema["items"]["type"] == 'object' %}
  <table class="table">
    <thead>
      <tr>
        {% set item_property_names = get_property_names_in_order(schema["items"]) %}
        {% for property_name in item_property_names %}
          {% set schema = schema["items"].properties[property_name] %}
          {% set property_path = property_path + ('?', property_name) %}
          <th scope="col">
            {% include "objects/table_property_label.html" %}
          </th>
        {% endfor %}
      </tr>
    </thead>
    <tbody>
      {% set has_diff = diff is not none and previous_schema is not none and not (diff is mapping) %}
      {% if data is not none or has_diff %}
        {% set loop_length = 0 %}
        {% if data is not none %}
          {% set loop_length = data | length %}
        {% endif %}
        {% if has_diff and diff | length > loop_length %}
          {% set loop_length = diff | length %}
        {% endif %}
        {% for unused in range(loop_length) %}
          {% if data is not none and (data | length) > loop.index0 %}
            {% set item = data[loop.index0] %}
          {% else %}
            {% set item = none %}
          {% endif %}
          {% set schema = schema['items'] %}
          {% set data = item %}
          {% if has_diff and diff | length > loop.index0  %}
            {% set diff = diff[loop.index0] %}
            {% if 'items' in previous_schema %}
              {% set previous_schema = previous_schema['items'] %}
            {% else %}
              {% set previous_schema = none %}
            {% endif %}
          {% else %}
            {% set diff = none %}
            {% set previous_schema = none %}
          {% endif %}
          {% set entry_index = loop.index0 %}
          {% if diff is not none %}
            {% if '_after' in diff and '_before' in diff %}
              {% set data_rows = [(diff['_before'], 'data-diff-before'), (diff['_after'], 'data-diff-after')] %}
            {% elif '_before' in diff %}
              {% set data_rows = [(diff['_before'], 'data-diff-before')] %}
            {% elif '_after' in diff %}
              {% set data_rows = [(diff['_after'], 'data-diff-after')] %}
            {% else %}
              {% set data_rows = [(data, '')] %}
            {% endif %}
          {% else %}
            {% set data_rows = [(data, '')] %}
          {% endif %}
          {% for data, row_class in data_rows %}
            <tr class="{{ row_class }}">
              {% for property_name in item_property_names %}
                <td>
                  {% set schema = schema.properties[property_name] %}
                  {% set property_path = property_path + (entry_index, property_name) %}
                  {% set id_prefix = id_prefix_for_property_path(property_path, id_prefix_root) %}
                  {% if diff is not none and previous_schema is not none and property_name in diff %}
                    {% set diff = diff[property_name] %}
                    {% if 'properties' in previous_schema and property_name in previous_schema['properties'] %}
                      {% set previous_schema = previous_schema['properties'][property_name] %}
                    {% else %}
                      {% set previous_schema = none %}
                    {% endif %}
                  {% else %}
                    {% set diff = none %}
                    {% set previous_schema = none %}
                  {% endif %}
                  {% if data is not none and property_name in data %}
                    {% set data = data[property_name] %}
                  {% else %}
                    {% set data = none %}
                  {% endif %}
                  {% include "objects/view/any.html" %}
                </td>
              {% endfor %}
            </tr>
          {% endfor %}
        {% 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] %}
    {% if max_used_fields > 0 %}
      <table class="table">
        <thead>
          <tr>
            {% for i in range(max_used_fields) %}
              <th>
                {{ _('Field %(index)s', index=i + 1) }}
              </th>
            {% endfor %}
          </tr>
        </thead>
        <tbody>
          {% for item in data %}
            {% if diff is not none and previous_schema is not none and not (diff is mapping) and diff | length > loop.index0  %}
              {% set diff = diff[loop.index0] %}
              {% if 'items' in previous_schema %}
                {% set previous_schema = previous_schema['items'] %}
              {% else %}
                {% set previous_schema = none %}
              {% endif %}
            {% else %}
              {% set diff = none %}
              {% set previous_schema = none %}
            {% endif %}
            {% set entry_index = loop.index0 %}
            {% set item_rows = [(item, '')] %}
            {% if diff is not none and diff is mapping %}
              {% if '_after' in diff and '_before' in diff %}
                {% set item_rows = [(diff['_before'], 'data-diff-after'), (diff['_after'], 'data-diff-before')] %}
              {% elif '_after' in diff %}
                {% set item_rows = [(diff['_after'], 'data-diff-after')] %}
              {% elif '_before' in diff %}
                {% set item_rows = [(diff['_before'], 'data-diff-before')] %}
              {% else %}
                {% set item_rows = [(item, '')] %}
              {% endif %}
            {% endif %}
            {% for item, item_class in item_rows %}
              <tr class="{{ item_class }}">
              {% for field_index, field in zip_longest(range(max_used_fields), item) %}
                <td>
                  {% set schema = schema["items"]["items"] %}
                  {% set property_path = property_path + (entry_index, loop.index0) %}
                  {% set id_prefix = id_prefix_for_property_path(property_path, id_prefix_root) %}
                  {% set data = field %}
                  {% if diff is not none and previous_schema is not none and not (diff is mapping) and diff | length > loop.index0  %}
                    {% set diff = diff[loop.index0] %}
                    {% if 'items' in previous_schema %}
                      {% set previous_schema = previous_schema['items'] %}
                    {% else %}
                      {% set previous_schema = none %}
                    {% endif %}
                  {% else %}
                    {% set diff = none %}
                    {% set previous_schema = none %}
                  {% endif %}
                  {% include "objects/view/any.html" %}
                </td>
              {% endfor %}
              </tr>
            {% endfor %}
          {% endfor %}
        </tbody>
        <tfoot>
          <tr>
            {% for i in range(max_used_fields) %}
              <th>
                {{ _('Field %(index)s', index=i + 1) }}
              </th>
            {% endfor %}
          </tr>
        </tfoot>
      </table>
    {% endif %}
  {% endif %}
  {% if data and data.export_edit_note %}
    <p class="text-muted"><i class="fa fa-share-alt" aria-hidden="true"></i> _('Note:') {{ data.export_edit_note }}</p>
  {% endif %}
</div>
