{#
Copyright 2024, 2025 New Vector Ltd.
Copyright 2024 The Matrix.org Foundation C.I.C.

SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
-#}

{% macro form(class="") -%}
  {%- if captcha|default(False) -%}
    <noscript>
      <div class="captcha-noscript">
        {{ _("mas.captcha.noscript") }}
      </div>
    </noscript>

    {%- if captcha.service == "recaptcha_v2" -%}
      <div class="g-recaptcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
    {%- elif captcha.service == "cloudflare_turnstile" -%}
      <div class="cf-turnstile {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
    {%- elif captcha.service == "hcaptcha" -%}
      <div class="h-captcha {{ class }}" data-sitekey="{{ captcha.site_key }}"></div>
    {%- else -%}
      {{ throw(message="Invalid captcha service setup") }}
    {%- endif %}
  {%- endif -%}
{% endmacro %}

{% macro head() -%}
  {%- if captcha|default(False) -%}
    {%- if captcha.service == "recaptcha_v2" -%}
      <script src="https://www.recaptcha.net/recaptcha/api.js" async defer></script>
    {%- elif captcha.service == "cloudflare_turnstile" -%}
      <script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
    {%- elif captcha.service == "hcaptcha" -%}
      <script src="https://js.hcaptcha.com/1/api.js?recaptchacompat=off" async defer></script>
    {%- else -%}
      {{ throw(message="Invalid captcha service setup") }}
    {%- endif %}
  {%- endif -%}
{%- endmacro %}
