{% extends "deliver_grant_funding/grant_base.html" %}
{% from "govuk_frontend_jinja/components/back-link/macro.html" import govukBackLink %}
{% from "govuk_frontend_jinja/components/table/macro.html" import govukTable %}

{% set type_constants = collection.type.constants %}
{% set active_item_identifier = type_constants.active_nav %}

{% set page_title = "Confirm grant recipients in " ~ session_data.name ~ " data set" %}

{% block beforeContent %}
  {% if session_data.is_replace %}
    {% set back_link = url_for("deliver_grant_funding.replace_data_set", grant_id=grant.id, collection_type=collection.type, collection_id=collection.id, data_source_id=session_data.data_source_id) %}
  {% else %}
    {% set back_link = url_for("deliver_grant_funding.upload_data_set", grant_id=grant.id, collection_type=collection.type, collection_id=collection.id) %}
  {% endif %}
  {{ govukBackLink({ "text": "Back", "href": back_link }) }}
{% 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">{{ collection.name }}</span>
        Confirm grant recipients in {{ session_data.name }} data set
      </h1>
      <p class="govuk-body">Grant recipients in the selected file do not match grant recipients in Deliver grant funding.</p>
      <p class="govuk-body">Check and confirm the grant recipients are correct or cancel and update the selected file before reuploading.</p>
    </div>
  </div>
  <div class="govuk-grid-row">
    <div class="govuk-grid-column-full">
      {%
        set table_head = [
          {"text": "Organisation ID"},
          {"text": "Grant recipient in selected file"},
          {"text": "Grant recipient in Deliver grant funding"}
        ]
      %}

      {% set rows = [] %}
      {% for mismatch in gr_mismatches %}
        {%
          do rows.append([
            {"text": mismatch.external_id},
            {"text": mismatch.csv_organisation_name},
            {"text": mismatch.service_organisation_name}
          ])
        %}
      {% endfor %}

      {{ govukTable({"head": table_head, "rows": rows}) }}

      <form method="POST" novalidate>
        <div class="govuk-button-group">
          {{ form.csrf_token }}
          {{ form.submit(params={"text": "Continue" }) }}
          <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('deliver_grant_funding.list_collection_data_sets', grant_id=grant.id, collection_type=collection.type, collection_id=collection.id) }}">Cancel</a>
        </div>
      </form>
    </div>
  </div>
{% endblock content %}
