{% load submission %}
{% load rputils %}

{% for ref in references %}
  {% if ref.block_label %}
    {{ ref.block_label_html }}
  {% endif %}
  
  {% if not ref.collection %}
    <div id="ref_{{ section.name }}_{{ ref.id_string }}"
         class="block-reference" style="
         min-height: {% if not section.wrap %}1.14em{% else %}0{% endif %}">
      {% if ref.inline_label %}{{ ref.inline_label_html }}{% endif %}
      
      {% dereference_block ref submission %}
    </div>
    
  {% else %}
    {% collection_items items ref.collection as collection %}
    
    {% for item in collection %}
      {% if not ref.inline_combine %}
        <div id="itemref_{{ ref.id }}_{{ item|underscore:'id' }}"
             class="ref_{{ section.name }}_{{ ref.id_string }} item-reference"
             data-ref="{{ ref.id }}" style="
        {% if not ref.combined and not forloop.first %}display: none;{% endif %}
        {% if not section.scroll and not ref.name %}
          flex-grow: 1;
          min-height: {% if not section.wrap %}1.14em{% else %}0{% endif %};
        {% endif %}">
      {% endif %}
      
      {% if not ref.is_file %}
        {% dereference_item_field ref item %}
        
      {% else %}
        {% dereference_item_file item as file_info %}
        
        {% with file=file_info.0 meta=file_info.1 %}
          {% include "./item_file.html" %}
        {% endwith %}
      {% endif %}
      
      {% if not ref.inline_combine %}</div>{% endif %}
    {% endfor %}
  {% endif %}

{% endfor %}

{% for collection_name, refs in selectors|items %}
  {% include "./item_selector.html" %}
{% endfor %}
