{% extends "base.html" %}

{% block page_title %}Package {{ config.event_type | title }} Requests{% endblock %}

{% block content %}

{% if request_events %}
  <table class="datatable">
    <thead>
      <tr>
        <th>File</th>
        <th>Type</th>
        <th>Reason</th>
        <th>Pipeline</th>
        <th>User</th>
        <th>Submitted</th>
        <th>Approve/Reject</th>
      </tr>
    </thead>
    <tbody>
    {% for req in request_events %}
      <tr>
        <td>{{ req.package }}</td>
        <td>{{ req.package.get_package_type_display }}</td>
        <td>{{ req.event_reason }}</td>
        <td>{{ req.pipeline }}</td>
        <td>{{ req.user_email }} (ID: {{ req.user_id}})</td>
        <td>{{ req.status_time }}</td>
        <td>
          <form action="{% url view_name %}" method="post">
            {% csrf_token %}
            {{ req.form.as_p }}
            <input type="submit" name="approve" value="Approve ({{ config.event_type | title }} package)" class='btn' />
            <input type="submit" name="reject" value="Reject (No change to package)" class='btn btn-primary' />
          </form>
        </td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
{% else %}
  <p>No requests pending.</p>
{% endif %}

{% if closed_requests %}
<h2>Closed Requests</h2>
  <table class="datatable">
    <thead>
      <tr>
        <th>File</th>
        <th>Type</th>
        <th>Reason</th>
        <th>Pipeline</th>
        <th>User</th>
        <th>Decision</th>
        <th>Reason</th>
        <th>Storage Admin</th>
        <th>Updated</th>
      </tr>
    </thead>
    <tbody>
    {% for req in closed_requests %}
      <tr>
        <td>{{ req.package }}</td>
        <td>{{ req.package.get_package_type_display }}</td>
        <td>{{ req.event_reason }}</td>
        <td>{{ req.pipeline }}</td>
        <td>{{ req.user_email }} (ID: {{ req.user_id}})</td>
        <td>{{ req.get_status_display }}</td>
        <td>{{ req.status_reason }}</td>
        <td>{{ req.admin_id }}</td>
        <td>{{ req.status_time }}</td>
      </tr>
    {% endfor %}
    </tbody>
  </table>
{% endif %}

{% endblock %}
