{% 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>{{ _fsdomain("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>{{ _fsdomain("Open your authenticator app on your device and scan the following qrcode to start receiving codes:") }}</p>
          <p><img alt="{{ _fsdomain("Passwordless QRCode") }}" id="qrcode" src="{{ url_for_security("us_qrcode", token=state) }}"></p>
        {% endif %}
        {% if code_sent %}
          <p>{{ _fsdomain("Code has been sent") }}
        {% endif %}
        {{ render_field(us_setup_form.submit) }}
      {% else %}
        <h3>{{  _fsdomain("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 %}
