{% from "components/components/button/macro.njk" import usaButton %}

{% macro page_footer(
  button_text=None,
  button_name=None,
  button_value=None,
  button_text_hidden_suffix=None,
  destructive=False,
  secondary_link=False,
  secondary_link_text=None,
  delete_link=False,
  delete_link_text="delete",
  centered_button=False
) %}
  <div class="page-footer margin-top-4">
    {% if button_text %}
      <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />

      {% set button_data = {"text": button_text} %}
      {% if destructive %}{% set _ = button_data.update({"classes": "govuk-button--warning page-footer__button"}) %}{% endif %}
      {% if centered_button %}{% set _ = button_data.update({"classes": "page-footer__button--centred"}) %}{% endif %}
      {% if button_name %}{% set _ = button_data.update({"name": button_name}) %}{% endif %}
      {% if button_value %}{% set _ = button_data.update({"value": button_value}) %}{% endif %}
      {% if button_text_hidden_suffix %}
        {% set _ = button_data.update({
          "text": "", "html": button_text + "<span class=\"usa-sr-only\"> " + button_text_hidden_suffix + "</span>"
        }) %}
      {% endif %}

      {{ usaButton(button_data) }}

    {% endif %}
    {% if delete_link %}
      <span class="page-footer-link {% if not button_text %}page-footer-delete-link-without-button{% endif %}">
        <a class="usa-link usa-link--destructive" href="{{ delete_link }}">{{ delete_link_text }}</a>
      </span>
    {% endif %}
    {% if secondary_link and secondary_link_text %}
    <div class="margin-top-4">
      <a class="usa-link font-body-sm" href="{{ secondary_link }}">{{ secondary_link_text }}</a>
    </div>
    {% endif %}
  </div>
{% endmacro %}

{% macro sticky_page_footer(button_text=None) %}
  <div class="js-stick-at-bottom-when-scrolling">
    {{ page_footer(button_text) }}
  </div>
{% endmacro %}
