{% extends "base.html" %}

{% block head_content %}
  <script defer type="text/javascript" language="javascript" src="{{ url_for('static', filename='js/reporter/aips.js') }}"></script>
{% endblock %}

{% block content %}

<div class="alert alert-header"><strong>AIPs ({{ pager.items|length }})</strong></div>

{% if storage_services %}

  <div class="float-end">
    <form action="{{ url_for('reporter.view_aips') }}" method="GET" class="pr-3" id="queryform">
      <i class="fa-solid fa-magnifying-glass"></i> Search <input name="query" id="query"/><input type="submit" hidden/>
    </form>
  </div>

  <div class="report-opts" style="margin-bottom: 0.2em;">
    <div>
      <span class="fixed-width-menu-span-left">
        <i class="fa-solid fa-database" aria-hidden="true"></i>
        Storage Service
      </span>
      <select id="ss" method="GET" action="/">
          {% for ss in storage_services %}
            {% if ss.id == storage_service.id %}
              <option value="{{ ss.id }}" SELECTED>{{ ss.name }}</option>
            {% else %}
              <option value="{{ ss.id }}">{{ ss.name }}</option>
            {% endif %}
          {% endfor %}
      </select>
    </div>
  </div>
  <div class="report-opts" style="margin-bottom: 1em;">
    <div>
      <span class="fixed-width-menu-span-left">
        <i class="fa-solid fa-box-archive" aria-hidden="true"></i>
        Location
      </span>
      <select id="sl" method="GET" action="/">
          <option value="">All locations</option>
          {% for sl in storage_locations %}
            {% if sl.id == storage_location.id %}
              <option value="{{ sl.id }}" SELECTED>{{ sl.description }}</option>
            {% else %}
              <option value="{{ sl.id }}">{{ sl.description }}</option>
            {% endif %}
          {% endfor %}
      </select>
    </div>
  </div>

  {% if pager.items %}

    <table id="aipstable" class="table table-striped table-bordered">
      <thead>
      <tr>
      <th><strong>Transfer name</strong></th>
      <th><strong>AIP UUID</strong></th>
      <th><strong>Size</strong></th>
      <th><strong>Creation date</strong></th>
      <th><strong>Originals</strong></th>
      <th><strong>Preservation copies</strong></th>
      <th><strong>Action</strong></th>
      </tr>

      {% for aip in pager.items %}
        <tr>
          <td>{{ aip.transfer_name }}</td>
          <td>{{ aip.uuid }}</td>
          <td>{{ aip.size | filesizeformat }}</td>
          <td>{{ aip.create_date }}</td>
          <td>{{ aip.original_file_count }}</td>
          <td>{{ aip.preservation_file_count }}</td>
          <td><a href='{{ url_for("reporter.view_aip", aip_id = aip.id) }}'><button type="button" class="btn btn-info">View</button></a></td>
        </tr>
      {% endfor %}
    </table>

  {% else %}

  <div style="padding:1em;">
      No data available. Run a Fetch Job to populate AIPscan with data from this Storage Service or select a different Storage Service.
  </div>

  {% endif %}

{% else %}

  <div style="padding:1em;">
      Storage Service information is not yet available for reporting. <a href="{{ url_for('aggregator.storage_services') }}">Configure a Storage Service</a> and run a Fetch Job to get started.</a>
  </div>

{% endif %}

{% 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_aips', page=1, **state_query_params) }}" 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_aips', page=pager.prev_num, **state_query_params) }}" 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_aips', page=pager.next_num, **state_query_params) }}" 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_aips', page=pager.pages, **state_query_params) }}" class="page-link">Last</a></li>
          </ul>
        </div>
      </div>
    </div>
  </div>

{% endif %}

{% endblock %}
