{% extends "admin/master.html" %}
{% from "govuk_frontend_jinja/components/tag/macro.html" import govukTag %}

{% block action_panel %}
  <div class="govuk-grid-row">
    <div class="govuk-grid-column-two-thirds">
      <h1 class="govuk-heading-l">Admin dashboard</h1>

      <div class="app-big-number-row">
        <a href="{{ url_for('deliver_grant_funding.list_grants') }}" class="app-big-number">
          <span class="app-big-number__number">{{ onboarding_grants|length }}</span>
          <span class="app-big-number__label">Onboarding grant{{ 's' if onboarding_grants|length != 1 else '' }}</span>
        </a>
        <a href="{{ url_for('deliver_grant_funding.list_grants') }}" class="app-big-number">
          <span class="app-big-number__number">{{ live_grants|length }}</span>
          <span class="app-big-number__label">Live grant{{ 's' if live_grants|length != 1 else '' }}</span>
        </a>
      </div>

      <div class="app-big-number-row">
        <a href="#scheduled-collections" class="app-big-number">
          <span class="app-big-number__number">{{ scheduled_collections|length }}</span>
          <span class="app-big-number__label">Scheduled collection{{ 's' if scheduled_collections|length != 1 else '' }}</span>
        </a>
        <a href="#open-collections" class="app-big-number">
          <span class="app-big-number__number">{{ open_collections|length }}</span>
          <span class="app-big-number__label">Open collection{{ 's' if open_collections|length != 1 else '' }}</span>
        </a>
        <a href="#overdue-collections" class="app-big-number">
          <span class="app-big-number__number">{{ overdue_collections|length }}</span>
          <span class="app-big-number__label">Overdue collection{{ 's' if overdue_collections|length != 1 else '' }}</span>
        </a>
      </div>

      <h2 class="govuk-heading-m govuk-!-margin-top-7">Important events just passed and coming up</h2>
      {% if timeline_events %}
        <table class="govuk-table">
          <thead class="govuk-table__head">
            <tr class="govuk-table__row">
              <th class="govuk-table__header" scope="col">Date</th>
              <th class="govuk-table__header" scope="col">Event</th>
              <th class="govuk-table__header" scope="col">Collection</th>
              <th class="govuk-table__header" scope="col">Grant</th>
            </tr>
          </thead>
          <tbody class="govuk-table__body">
            {% for event in timeline_events %}
              <tr class="govuk-table__row">
                <td class="govuk-table__cell">
                  {{ format_date_short(event.date) }}
                  {% if event.is_today %}
                    {{ govukTag({"text": "today", "classes": "govuk-tag--green"}) }}
                  {% elif event.is_past %}
                    {{ govukTag({"text": "past", "classes": "govuk-tag--grey"}) }}
                  {% else %}
                    {{ govukTag({"text": "soon", "classes": "govuk-tag--blue"}) }}
                  {% endif %}
                </td>
                <td class="govuk-table__cell">
                  {% if event.type == "opening" %}
                    Open for submissions
                  {% elif event.type == "closing" %}
                    Send overdue emails
                  {% elif event.type == "reminder" %}
                    Send reminder emails
                  {% endif %}
                </td>
                <td class="govuk-table__cell">
                  <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('collection_lifecycle.tasklist', grant_id=event.collection.grant_id, collection_id=event.collection.id) }}">{{ event.collection.name }}</a>
                </td>
                <td class="govuk-table__cell"><a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('deliver_grant_funding.grant_details', grant_id=event.collection.grant_id) }}">{{ event.collection.grant.name }}</a></td>
              </tr>
            {% endfor %}
          </tbody>
        </table>
      {% else %}
        <p class="govuk-body">No events in the last week or the next.</p>
      {% endif %}

      <h2 class="govuk-heading-m govuk-!-margin-top-7">Collections</h2>
      <h3 class="govuk-heading-s" id="scheduled-collections">Scheduled</h3>
      {% if scheduled_collections %}
        <ul class="govuk-list govuk-list--bullet">
          {% for collection in scheduled_collections %}
            <li>
              <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('collection_lifecycle.tasklist', grant_id=collection.grant_id, collection_id=collection.id) }}">{{ collection.name }}</a>
              ({{ collection.grant.name }})
            </li>
          {% endfor %}
        </ul>
      {% else %}
        <p class="govuk-body">None.</p>
      {% endif %}

      <h3 class="govuk-heading-s" id="open-collections">Open</h3>
      {% if open_collections %}
        <ul class="govuk-list govuk-list--bullet">
          {% for collection in open_collections %}
            <li>
              <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('collection_lifecycle.tasklist', grant_id=collection.grant_id, collection_id=collection.id) }}">{{ collection.name }}</a>
              ({{ collection.grant.name }})
            </li>
          {% endfor %}
        </ul>
      {% else %}
        <p class="govuk-body">None.</p>
      {% endif %}

      <h3 class="govuk-heading-s" id="overdue-collections">Overdue</h3>
      {% if overdue_collections %}
        <ul class="govuk-list govuk-list--bullet">
          {% for collection in overdue_collections %}
            <li>
              <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('collection_lifecycle.tasklist', grant_id=collection.grant_id, collection_id=collection.id) }}">{{ collection.name }}</a>
              ({{ collection.grant.name }}) &mdash; ended {{ format_date_short(collection.submission_period_end_date) }}
            </li>
          {% endfor %}
        </ul>
      {% else %}
        <p class="govuk-body">None.</p>
      {% endif %}
    </div>
  </div>
{% endblock %}
