{% from "common/partials/mhclg-test-banner.html" import mhclgInlinePageTestDataBanner %}
{% from "govuk_frontend_jinja/components/back-link/macro.html" import govukBackLink %}
{% extends "deliver_grant_funding/grant_base.html" %}

{% set page_title = "Reopen submission - " ~ helper.long_collection_name %}
{% set type_constants = helper.submission.collection.type.constants %}
{% set active_item_identifier = type_constants.active_nav %}

{% block beforeContent %}
  {% if helper.is_test %}
    {{ mhclgInlinePageTestDataBanner("Test submission") }}
  {% endif %}
  {{
    govukBackLink({
      "text": "Back",
      "href": url_for(
        "deliver_grant_funding.request_or_allow_changes" if feature_flags.PRE_AWARD.is_enabled else "deliver_grant_funding.view_submission",
        grant_id=grant.id,
        submission_id=helper.submission.id
      )
    })
  }}
{% endblock beforeContent %}

{% block content %}
  <div class="govuk-grid-row">
    <div class="govuk-grid-column-two-thirds">
      <h1 class="govuk-heading-l">
        <span class="govuk-caption-l">{{ helper.submission.grant_recipient.organisation.name if helper.submission.grant_recipient else helper.submission.created_by.email }}</span>
        Why are you reopening this {{ helper.long_collection_name }} submission?
      </h1>
      <p class="govuk-body">We will send an email with your reason for reopening to:</p>
      <ul class="govuk-list govuk-list--bullet">
        {% if helper.collection.requires_certification %}
          {% for user in helper.submission.grant_recipient.unique_data_providers_and_certifiers | sort(attribute="name") %}
            <li>{{ user.name }} ({{ user.email }})</li>
          {% endfor %}
        {% else %}
          {% for user in helper.submission.grant_recipient.data_providers | sort(attribute="name") %}
            <li>{{ user.name }} ({{ user.email }})</li>
          {% endfor %}
        {% endif %}
      </ul>
      <form method="post" novalidate>
        {% set label_html %}
          <p class="govuk-visually-hidden">Why are you reopening the submission?</p>
        {% endset %}
        {{ form.csrf_token }}
        {{
          form.reopened_reason(
            params={
              "label":{
                "html": label_html
              },
              "maxwords": form.REASON_MAX_WORDS
            }
          )
        }}
        <div class="govuk-button-group">
          {{ form.submit }}
          <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('deliver_grant_funding.view_submission', grant_id=grant.id, submission_id=helper.submission.id) }}">Cancel</a>
        </div>
      </form>
    </div>
  </div>
{% endblock content %}
