{% extends "standard-form.njk" %}

{% from "radios/macro.njk" import govukRadios %}

{% set errorMap = {
        'address-and-grid-reference-mismatch': {
          'any.required': { ref: '#address-and-grid-reference-mismatch', text: 'You have not selected an option' }
        }
    }
%}

{% set title = "Site address and National Grid Reference do not match" %}

{% macro getSiteAddress(siteAddress) %}

  {% if (siteAddress) %}
    <b>Address</b> <br> <span>{{ siteAddress | safe }}</span> <br>
  {% endif %}
    
{% endmacro %}

{% macro getGridReference(gridReference) %}

  {% if (gridReference) %}
    <b>National Grid Reference</b> <br> <span>{{ gridReference }}</span> <br>
  {% else %}
    <b>National Grid Reference</b> <br>
  {% endif %}
    
{% endmacro %}

{% block pageContent %}

  <p class="govuk-body">The site address and national grid reference must be at the same location.</p>


  {{ govukRadios({
      name: "address-and-grid-reference-mismatch",
      errorMessage: { text: 'Select an option' } if error['address-and-grid-reference-mismatch'],
      fieldset: {
        legend: {
          text: "Which one do you want to change?",
          isPageHeading: true,
          classes: "govuk-fieldset__legend--m"
        }
      },
      items: [
        {
          value: "address",
          html: getSiteAddress(data.siteAddress),
          checked: payload['address-and-grid-reference-mismatch'] === 'address'
        },
        {
          value: "gridReference",
          text: getGridReference(data.gridReference),
          checked: payload['address-and-grid-reference-mismatch'] === 'gridReference'
        },
        {
          divider: "or"
        },
        {
          value: "correct",
          text: "These are correct",
          checked: payload['address-and-grid-reference-mismatch'] === 'correct',
          hint: {
            text: "Your application may take longer to process if you don't give accurate site locations."
          }
        }
      ]
    })
  }}

{% endblock %}
