{% from "nhsuk/macros/attributes.njk" import nhsukAttributes %}
{% from "nhsuk/components/legend/macro.njk" import legend %}

{#- Set classes for this component #}
{%- set classNames = "nhsuk-fieldset" -%}

{%- if params.classes %}
  {% set classNames = classNames ~ " " ~ params.classes %}
{% endif -%}

<fieldset
  {{- nhsukAttributes({
    class: classNames,
    id: {
      value: params.id,
      optional: true
    },
    role: {
      value: params.role,
      optional: true
    },
    "aria-describedby": {
      value: params.describedBy if params.describedBy else false,
      optional: true
    }
  }) -}}

  {{- nhsukAttributes(params.attributes) }}>
  {{ legend(params.legend) | trim | indent(2) }}
{% if caller %} {#- if statement allows usage of `call` to be optional -#}
  {{ caller() }}
{% elif params.html %}
  {{ params.html | safe }}
{% endif %}
</fieldset>
