{% from "govuk_frontend_jinja/components/breadcrumbs/macro.html" import govukBreadcrumbs %}

{# render the breadcrumb for deliver grant funding #}
{% macro deliver_grant_funding_collection_breadcrumb(grant=None, data_set=None, collection=None, form=None, immediate_parent_breadcrumb_item=None, this_page_breadcrumb_item=None, truncated=False, collection_type=None) %}
  {% set collection_type = (collection.type if collection) or (data_set.collection.type if data_set) or (form.collection.collection_type if form) or collection_type %}
  {% set type_constants = collection_type.constants %}
  {% set items=[] %}
  {% if grant %}
    {% set collections_html %}
      <span>{{ type_constants.plural | uppercase_first }}</span>
      <span class="govuk-visually-hidden">for {{ grant.name }}</span>
    {% endset %}
    {% do items.append({"html": collections_html, "href": url_for(type_constants.list_endpoint, grant_id=grant.id)}) %}
  {% endif %}

  {% if data_set %}
    {% set data_set_name_html %}
      <span>Data sets</span>
      <span class="govuk-visually-hidden"> for {{ data_set.collection.name }}</span>
    {% endset %}
    {% do items.append({"html": data_set_name_html, "href": url_for("deliver_grant_funding.list_collection_data_sets", grant_id=grant.id, collection_type=data_set.collection.type, collection_id=data_set.collection_id) }) %}
  {% endif %}

  {% if collection %}
    {% set collection_name_html %}
      <span class="govuk-visually-hidden">{{ type_constants.singular | uppercase_first }}:</span>
      <span>{{ collection.name }}</span>
    {% endset %}
    {% do items.append({"html": collection_name_html, "href": url_for("deliver_grant_funding.list_collection_sections", grant_id=grant.id, collection_type=collection.type, collection_id=collection.id)}) %}
  {% endif %}

  {% if form %}
    {% set form_name_html %}
      <span class="govuk-visually-hidden">Section:</span>
      <span>{{ form.title }}</span>
    {% endset %}
    {% do items.append({"html": form_name_html, "href": url_for("deliver_grant_funding.list_section_questions", grant_id=grant.id, form_id=form.id) }) %}
  {% endif %}

  {% if truncated == True %}
    {% set ellipsis_html %}
      <span class="govuk-visually-hidden">1 question group hidden</span>
      <span aria-hidden="true">...</span>
    {% endset %}
    {% do items.append({"html": ellipsis_html}) %}
  {% endif %}

  {% if immediate_parent_breadcrumb_item != None %}
    {% do items.append(immediate_parent_breadcrumb_item) %}
  {% endif %}

  {% if this_page_breadcrumb_item %}
    {% do items.append(this_page_breadcrumb_item) %}
  {% endif %}

  {{
    govukBreadcrumbs(params={
    "items": items
    })
  }}
{% endmacro %}
