{#
Copyright 2024, 2025 New Vector Ltd.
Copyright 2021-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.
-#}

{% extends "base.html" %}

{% block content %}
  <header class="page-heading">
    <div class="icon">
      {{ icon.user_profile_solid() }}
    </div>

    <div class="header">
      <h1 class="title">{{ _("mas.register.create_account.heading") }}</h1>
    </div>
  </header>

  <form method="POST" class="cpd-form-root">
    {% for error in form.errors %}
      {# Special case for the captcha error, as we want to put it at the bottom #}
      {% if error.kind != "captcha" %}
        <div class="text-critical font-medium">
          {{ errors.form_error_message(error=error) }}
        </div>
      {% endif %}
    {% endfor %}

    <input type="hidden" name="csrf" value="{{ csrf_token }}" />

    {% call(f) field.field(label=_("common.username"), name="username", form_state=form) %}
      <input {{ field.attributes(f) }} class="cpd-text-control" type="text" autocomplete="username" autocorrect="off" autocapitalize="none" required />
    {% endcall %}

    {% call(f) field.field(label=_("common.email_address"), name="email", form_state=form) %}
      <input {{ field.attributes(f) }} class="cpd-text-control" type="email" autocomplete="email" required />
    {% endcall %}

    {% call(f) field.field(label=_("common.password"), name="password", form_state=form) %}
      <input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required />
    {% endcall %}

    {% call(f) field.field(label=_("common.password_confirm"), name="password_confirm", form_state=form) %}
      <input {{ field.attributes(f) }} class="cpd-text-control" type="password" autocomplete="new-password" required />
    {% endcall %}

    {% if branding.tos_uri %}
      {% call(f) field.field(label=_("mas.register.terms_of_service", tos_uri=branding.tos_uri), name="accept_terms", form_state=form, inline=true, class="my-4") %}
        <div class="cpd-form-inline-field-control">
          <div class="cpd-checkbox-container">
            <input {{ field.attributes(f) }} class="cpd-checkbox-input" type="checkbox" required />
            <div class="cpd-checkbox-ui">
              {{ icon.check() }}
            </div>
          </div>
        </div>
      {% endcall %}
    {% endif %}

    {{ captcha.form(class="mb-4 self-center") }}

    {% for error in form.errors %}
      {# Special case for the captcha error #}
      {% if error.kind == "captcha" %}
        <div class="text-critical font-medium text-center -mt-4 mb-4">
          {{ errors.form_error_message(error=error) }}
        </div>
      {% endif %}
    {% endfor %}

    {{ button.button(text=_("action.continue")) }}

    {% set params = next["params"] | default({}) | to_params(prefix="?") %}
    {{ button.link_tertiary(text=_("mas.register.call_to_login"), href="/login" ~ params) }}
  </form>
{% endblock content %}
