{% extends "admin/master.html" %}
{% import 'admin/layout.html' as layout with context %}
{% from "govuk_frontend_jinja/components/back-link/macro.html" import govukBackLink %}
{% from 'govuk_frontend_jinja/components/error-summary/macro.html' import govukErrorSummary %}
{% from 'govuk_frontend_jinja/components/warning-text/macro.html' import govukWarningText %}
{% from "govuk_frontend_jinja/components/summary-list/macro.html" import govukSummaryList %}

{% block beforeContent %}
  {{ govukBackLink({"text": "Back", "href": url_for('collection_lifecycle.tasklist', grant_id=grant.id, collection_id=collection.id) }) }}
{% endblock %}

{% block action_panel %}
  <div class="govuk-grid-row">
    <div class="govuk-grid-column-one-half">
      {{ layout.messages() }}

      {% if form.errors %}
        {{ govukErrorSummary(wtforms_errors(form)) }}
      {% endif %}

      <h1 class="govuk-heading-l">
        <span class="govuk-caption-l">{{ grant.name }}</span>
        Sign off and lock {{ collection.type.constants.singular }}
      </h1>
      <p class="govuk-body">Sign off and lock the {{ collection.type.constants.singular }} to prevent further edits once the grant policy team has signed off on the form.</p>
      <p class="govuk-body">
        A Platform admin member must manually open the signed off report for submissions on
        {{ format_date_short(collection.submission_period_start_date) if collection.submission_period_start_date else "the first day of the submission period" }} and send emails to data providers.
      </p>

      {% if data_set_names_with_missing_data %}
        {% set data_set_or_sets %}{% trans count=data_set_names_with_missing_data|length %}data set{% pluralize %}data sets{% endtrans %}{% endset %}
        {% set missing_data_warning %}
          There is missing data in {{ data_set_names_with_missing_data|comma_join_items("and") }} {{ data_set_or_sets }} referenced in the form. Grant recipients with missing data will not be able to complete the report until their missing
          data is uploaded.
        {% endset %}
        {{ govukWarningText({"text": missing_data_warning}) }}
      {% endif %}
      {% if recipients_missing_data_providers | length > 0 %}
        {{
          govukWarningText({
            "text": "There are grant recipients with no data providers set up: " ~ (recipients_missing_data_providers | join(", ") ),
            "iconFallbackText": "Warning"
          })
        }}
      {% endif %}

      {{
        govukSummaryList({
          "rows": [{
            "key": { "text": collection.type.constants.singular | capitalize + " name" },
            "value": { "text": collection.name },
          }, {
            "key": { "text": collection.type.constants.singular | capitalize + " period" },
            "value": { "text": format_date_range(collection.reporting_period_start_date, collection.reporting_period_end_date) if collection.reporting_period_start_date and collection.reporting_period_end_date else "Not set" },
          }, {
            "key": { "text": "Submission period" },
            "value": { "text": format_date_range(collection.submission_period_start_date, collection.submission_period_end_date) if collection.submission_period_start_date and collection.submission_period_end_date else "Not set" },
          }
          ],
          "classes": "app-!-border-top-line govuk-!-margin-bottom-8"
        })
      }}
      <form method="post" novalidate>
        {{ form.csrf_token }}
        {{ form.submit }}
      </form>
    </div>
  </div>
{% endblock %}
