{% extends "base.html" %}

{% block content %}

<div class="alert alert-secondary">
  <strong>AIP: {{ aip.transfer_name }}-{{ aip.uuid }}</strong>
  <br>
  Storage service:
  <a href="{{ url_for('aggregator.storage_service', storage_service_id=storage_service.id) }}">
    {{ storage_service.name }}
  </a>
  (<a href="{{ url_for('reporter.view_aips', storage_service_id=storage_service.id) }}">
    {{ aips_count }} AIPs
  </a>)
  <br>
  Storage location: {{ storage_location.description }} ({{ storage_location.uuid }})
  <br>
  Origin pipeline: <a href="{{ origin_pipeline.dashboard_url }}">{{ origin_pipeline.dashboard_url }}</a>
  <br>
  Creation date: {{ aip.create_date }}
  <br>
  Originals: {{ original_file_count }}
  <br>
  Preservation copies: {{ preservation_file_count }}
  <br>
  <a href="{{ url_for('reporter.download_mets', aip_id=aip.id) }}">Download METS</a>
</div>

<h3>Original files</h3>

<table id="aipstable" class="table table-striped table-bordered">
  <thead>
  <tr>
  <th><strong>Name</strong></th>
  <th><strong>UUID</strong></th>
  <th><strong>Size</strong></th>
  <th><strong>Last modified</strong></th>
  <th><strong>PUID</strong></th>
  <th><strong>Format</strong></th>
  <th><strong>View</strong></th>
  </tr>
  </thead>
  {% if originals %}
    {% for original in originals %}
      <tr>
        <td>{{ original["name"] }}</td>
        <td>{{ original["uuid"] }}</td>
        <td>{{ original["size"] | filesizeformat }}</td>
        <td>{{ original["date_created"] }}</td>
        {% if original["puid"] %}
          <td>
            <a href='http://www.nationalarchives.gov.uk/PRONOM/{{ original["puid"] }}'
                target="_blank">{{ original["puid"] }}</a>
          </td>
        {% else %}
          <td>
            None
          </td>
        {% endif %}
        <td>
          {{ original["file_format"] }}
          {% if original["format_version"] %}
            <span> ({{ original["format_version"] }})</span>
          {% endif %}
        </td>
        <td>
          <a href='{{ url_for("reporter.view_file", file_id=original["id"]) }}'>
            <button type="button" class="btn btn-info" style="margin-bottom: 5px;">
              Details
            </button>
          </a>
        {% if original["preservation_file_id"] %}
          <a href='{{ url_for("reporter.view_file", file_id=original["preservation_file_id"]) }}'>
            <button type="button" class="btn btn-info" style="margin-bottom: 5px;">
              Preservation file
            </button>
          </a>
        {% endif %}
      </td>
      </tr>
    {% endfor %}
  {% endif %}
</table>

{% if pager.total %}

  <div class="dataTables_wrapper">
    <div class="row">
      <div class="col-sm-12 col-md-5">
        <div class="dataTables_info" id="aiptable_info" role="status" aria-live="polite">Showing {{ first_item }} to {{ last_item }} of {{ pager.total }} entries</div>
      </div>
      <div class="col-sm-12 col-md-7">
        <div class="dataTables_paginate paging_full_numbers" id="aiptable_paginate">
          <ul class="pagination">
            <li class="paginate_button page-item first {% if pager.page == 1 %}disabled{% endif %}"><a href="{{ url_for('reporter.view_aip', aip_id=aip.id, page=1) }}" class="page-link">First</a></li>
            <li class="paginate_button page-item previous {% if pager.prev_num is none %}disabled{% endif %}"><a href="{{ url_for('reporter.view_aip', aip_id=aip.id, page=pager.prev_num) }}" class="page-link">Previous</a></li>
            <li class="paginate_button page-item active"><a href="#" class="page-link">{{ pager.page }}</a></li>
            <li class="paginate_button page-item next {% if pager.next_num is none %}disabled{% endif %}"><a href="{{ url_for('reporter.view_aip', aip_id=aip.id, page=pager.next_num) }}" class="page-link">Next</a></li>
            <li class="paginate_button page-item last {% if pager.page == pager.pages %}disabled{% endif %}"><a href="{{ url_for('reporter.view_aip', aip_id=aip.id, page=pager.pages) }}" class="page-link">Last</a></li>
          </ul>
        </div>
      </div>
    </div>
  </div>

{% endif %}

{% endblock %}
