{% extends "deliver_grant_funding/grant_base.html" %}
{% from "govuk_frontend_jinja/components/back-link/macro.html" import govukBackLink %}
{% from "govuk_frontend_jinja/components/error-summary/macro.html" import govukErrorSummary %}

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

{% set page_title = "Upload new data set to " + collection.name %}

{% block beforeContent %}
  {% set back_link = url_for("deliver_grant_funding.list_collection_data_sets", grant_id=grant.id, collection_type=collection.type, collection_id=collection.id) %}
  {{ govukBackLink({ "text": "Back", "href": back_link }) }}
{% endblock beforeContent %}

{% block content %}
  <div class="govuk-grid-row">
    <div class="govuk-grid-column-two-thirds">
      {% if gr_errors %}
        {% set error_list = [] %}
        {% for error in gr_errors %}
          {% do error_list.append({"text": error, "href": "#file"}) %}
        {% endfor %}
        {{
          govukErrorSummary({
            "titleText": "There is a problem",
            "errorList": error_list
          })
        }}
      {% endif %}
      <h1 class="govuk-heading-l">
        <span class="govuk-caption-l">{{ collection.name }}</span>
        Upload new data set
      </h1>
      <p class="govuk-body">
        To upload a complete data set, <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('deliver_grant_funding.grant_details', grant_id=grant.id) }}">check the grant recipients</a> have been set up first before uploading
        the file. The grant recipients will be reflected in the
        <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('deliver_grant_funding.download_grant_recipient_data_set_template', grant_id=grant.id, collection_type=collection.type, collection_id=collection.id) }}"
          >data set template (CSV)</a
        >.
      </p>
      <p class="govuk-body">If you are missing some grant recipients or data, you can still upload the file and replace it later.</p>
      <form method="POST" enctype="multipart/form-data" novalidate>
        {{ form.csrf_token }}
        {{ form.name }}
        {{ form.file(params={"javascript": true, "attributes": {"accept": "text/csv" } }) }}
        <p class="govuk-body">Only CSV (.csv) files can be uploaded for data sets.</p>
        <div class="govuk-button-group">
          {{ form.submit(params={"text": "Continue and format data" }) }}
          <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 %}
