{% 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 = "Request changes - " ~ 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", 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>
        Changes needed to {{ helper.long_collection_name }}
      </h1>
      <p class="govuk-body">We will send an email with the change request 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>
        {{ form.csrf_token }}
        {{
          form.section_ids(params={
            "fieldset": {
              "legend": {
                "text": form.section_ids.label,
                "classes": "govuk-fieldset__legend--m"
              }
            }
          })
        }}
        {{
          form.changes_requested_reason(params={
            "label": {
              "text": form.changes_requested_reason.label,
              "classes": "govuk-label--m"
            },
            "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 %}
