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

{% from "govuk/components/radios/macro.njk" import govukRadios %}
{% from "govuk/components/summary-list/macro.njk" import govukSummaryList %}

{% set errorMap = {
        'licence': {
          'any.required': { ref: '#licence', text: 'You have not selected an option' }
        }
    }
%}

{% set title = "Previous badger mitigation licences" %}

{% block pageContent %}
{% set legendText = "Do you want to add another previous badger mitigation licence?" %}

{% if data.allRemoved %}

{{ govukSummaryList({
      rows: [
        {
          key: {
            text: "Badger mitigation licence"
          },
          value: {
            text: "No licence added"
          },
          actions: {
          }
        }
      ]
    }) }}
{% else %}
    {% for licence in data.previousLicences %}
        {{ govukSummaryList({
          rows: [
            {
              key: {
                text: "Badger mitigation licence"
              },
              value: {
                text: licence
              },
              actions: {
                items: [
                  {
                    href: "/remove-licence?licence=" + licence,
                    text: "Remove"
                  }
                ]
              }
            }
          ]
        }) }}
    {% endfor %}
{% endif %}

{{ govukRadios({
  idPrefix: "licence",
  name: "licence",
  fieldset: {
    legend: {
      text: "Do you want to add a previous badger mitigation licence?" if data.allRemoved else "Do you want to add another previous badger mitigation licence?",
      isPageHeading: false,
      classes: "govuk-fieldset__legend--m"
    }
  },
  errorMessage: {
    text: "Select an option"
  } if error['licence'] === 'any.required',
  items: [
    {
      value: "yes",
      text: "Yes"
    },
    {
      value: "no",
      text: "No"
    }
  ]
}) }}

{% endblock %}
