{% from "govuk_frontend_jinja/components/notification-banner/macro.html" import govukNotificationBanner %}

{% macro dependency_banner(error, interpolate) %}
  {% set question_link = url_for("deliver_grant_funding.edit_question", grant_id=error.grant_id, question_id=error.question_id) if not error.question_is_group else url_for("deliver_grant_funding.list_group_questions", grant_id=error.grant_id, group_id=error.question_id) %}
  {% set depends_on_link = url_for("deliver_grant_funding.edit_question", grant_id=error.grant_id, question_id=error.depends_on_question_id) if not error.depends_on_question_is_group else url_for("deliver_grant_funding.list_group_questions", grant_id=error.grant_id, group_id=error.depends_on_question_id) %}


  {% set banner_html %}
    <p class="govuk-body govuk-!-font-weight-bold">{{ error.message }}</p>
    <p class="govuk-body govuk-!-font-weight-bold">
      {{ "Question group" if error.question_is_group else "Question" }}:
      <a class="govuk-notification-banner__link" href="{{ question_link }}">{{ interpolate(error.question_text) }}</a>
    </p>
    <p class="govuk-body govuk-!-font-weight-bold">
      Depends on the answer to:
      <a class="govuk-notification-banner__link" href="{{ depends_on_link }}">{{ interpolate(error.depends_on_question_text) }}</a>
    </p>
    {% if "depends_on_items_text" in error %}
      <p class="govuk-body govuk-!-font-weight-bold">Depends on the options: {{ interpolate(error.depends_on_items_text) }}</p>
    {% endif %}
  {% endset %}

  {{ govukNotificationBanner(params={"role": "alert", "titleText": "Error", "classes": "app-notification-banner--destructive", "html": banner_html}) }}
{% endmacro %}

{% macro section_dependency_banner(error) %}
  {% set question_link = url_for("deliver_grant_funding.list_section_questions", grant_id=error.grant_id, form_id=error.form_id) %}
  {% set depends_on_link = url_for("deliver_grant_funding.list_section_questions", grant_id=error.grant_id, form_id=error.depends_on_form_id) %}


  {% set banner_html %}
    <p class="govuk-body govuk-!-font-weight-bold">{{ error.message }}</p>
    <p class="govuk-body govuk-!-font-weight-bold">
      Section:
      <a class="govuk-notification-banner__link" href="{{ question_link }}">{{ error.form_title }}</a>
    </p>
    <p class="govuk-body govuk-!-font-weight-bold">
      Depends on answers in section:
      <a class="govuk-notification-banner__link" href="{{ depends_on_link }}">{{ error.depends_on_form_title }}</a>
    </p>
  {% endset %}

  {{ govukNotificationBanner(params={"role": "alert", "titleText": "Error", "classes": "app-notification-banner--destructive", "html": banner_html}) }}
{% endmacro %}

{% macro section_component_dependency_banner(error, interpolate) %}
  {% set banner_html %}
    <p class="govuk-body govuk-!-font-weight-bold">{{ error.message }}:</p>
    <ul class="govuk-list govuk-list--bullet">
      {% for ref in error.references %}
        {% set component_link = url_for("deliver_grant_funding.edit_question", grant_id=error.grant_id, question_id=ref.component_id) if not ref.is_group else url_for("deliver_grant_funding.list_group_questions", grant_id=error.grant_id, group_id=ref.component_id) %}
        {% set section_link = url_for("deliver_grant_funding.list_section_questions", grant_id=error.grant_id, form_id=ref.section_id) %}
        <li class="govuk-body govuk-!-font-weight-bold">
          {% if ref.reference_type in ("validation", "condition") %}{{ ref.reference_type | uppercase_first }} for{% endif %}
          <a class="govuk-notification-banner__link" href="{{ component_link }}">{{ interpolate(ref.component_text) }}</a>
          in
          <a class="govuk-notification-banner__link" href="{{ section_link }}">{{ ref.section_title }}</a>
        </li>
      {% endfor %}
    </ul>
    <p class="govuk-body govuk-!-font-weight-bold">Delete the other section references to delete this section.</p>
  {% endset %}

  {{ govukNotificationBanner(params={"role": "alert", "titleText": "Error", "classes": "app-notification-banner--destructive", "html": banner_html}) }}
{% endmacro %}
