{% load i18n %}
{% load form_helper %}
{% load permission_helper %}

<div class="table-responsive">
<table class="table">
  <thead>
    <tr>
      <th>{% trans "Field" %}</th>
      {% for key, proposal in proposals.items %}
        <th>
          <span title="{{ proposal.timestamp }}">
            {% if request.user.is_staff and request.user|has_perm:"account.view_user" %}
              {{ proposal.user.get_full_name }} ({{ proposal.user.email }})
            {% else %}
              {{ proposal.timestamp | date:"SHORT_DATETIME" }}
            {% endif %}
          </span>
        </th>
      {% endfor %}
    </tr>
  </thead>
  <tbody>
    {% if proposals %}
    <tr>
      <td>
        {% trans "Proposal" %}
      </td>
      {% for key, proposal in proposals.items %}
        <td>
          <label>
            <input type="radio" name="proposal_id" class="proposal" value="{{ key }}">
              {% trans "Turn into update draft" %}
          </label>
        </td>
      {% endfor %}
    </tr>
    {% endif %}
    {% for field in form %}
      <tr>
        <td>{{ field.label }}</td>
        {% for key, proposal in proposals.items %}
          {% with val=proposal.data|get_item_by_key:field.name %}
          <td>
            {% with label_name=field.name|add:"_label" %}
              {% if proposal.data|get_item_by_key:label_name %}
                {{ proposal.data|get_item_by_key:label_name }}
              {% else %}
                {{ val|urlize|linebreaksbr }}
              {% endif %}
            {% endwith %}
          </td>
          {% endwith %}
        {% endfor %}
      </tr>
      {{ form.field }}
    {% endfor %}

    {% if proposals %}
    <tr>
      <td>
        {% trans "Delete proposal" %}
      </td>
      {% for key, proposal in proposals.items %}
        <td>
          <label>
            <input type="checkbox" name="proposal_delete" value="{{ proposal.user.id }}">
            {% trans "Delete" %}
          </label>
        </td>
      {% endfor %}
    </tr>
    {% endif %}
  </tbody>

</table>
</div>
