{% extends "security/base.html" %}
{% from "security/_macros.html" import render_field_with_errors, render_field, render_field_errors %}

{% block content %}
    {% include "security/_messages.html" %}
    <h1>{{ _("Setup Unified Sign In options") }}</h1>
    <form action="{{ url_for_security("us_setup") }}" method="POST"
          name="us_setup_form">
      {{ us_setup_form.hidden_tag() }}
      {% if setup_methods %}
        <p>Currently Active options:
        {% if active_methods %}
          {{ ", ".join(active_methods) }}
        {% else %}
          None.
        {% endif %}
        </p>
        {% for subfield in us_setup_form.chosen_method %}
          {% if subfield.data in available_methods %}
              {{ render_field_with_errors(subfield) }}
          {% endif %}
        {% endfor %}
        {{ render_field_errors(us_setup_form.chosen_method) }}
        {% if "sms" in available_methods %}
          {{ render_field_with_errors(us_setup_form.phone) }}
        {% endif %}
        {% if chosen_method == "authenticator" %}
          <p>{{ _("Open your authenticator app on your device and scan the following qrcode to start receiving codes:") }}</p>
          <p><img alt="{{ _("Passwordless QRCode") }}" id="qrcode" src="{{ url_for_security("us_qrcode", token=state) }}"></p>
        {% endif %}
        {% if code_sent %}
          <p>{{ _("Code has been sent") }}
        {% endif %}
        {{ render_field(us_setup_form.submit) }}
      {% else %}
        <h3>{{  _("No methods have been enabled - nothing to setup") }}</h3>
      {% endif %}
    </form>
    {%  if state %}
      <form action="{{ url_for_security("us_setup_validate", token=state) }}" method="POST"
          name="us_setup_validate_form">
        {{ us_setup_validate_form.hidden_tag() }}
        {{ render_field_with_errors(us_setup_validate_form.passcode) }}
        {{ render_field(us_setup_validate_form.submit) }}
      </form>
    {%  endif %}
{% endblock %}
